This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 132898 - Component must be public to be member of another component
Summary: Component must be public to be member of another component
Status: NEW
Alias: None
Product: guibuilder
Classification: Unclassified
Component: Code (show other bugs)
Version: 6.x
Hardware: All Windows XP
: P3 blocker (vote)
Assignee: issues@guibuilder
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-15 15:51 UTC by stevenable
Modified: 2008-05-29 15:51 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Zip containing example project demonstrating the problem (12.80 KB, application/octet-stream)
2008-04-15 15:53 UTC, stevenable
Details

Note You need to log in before you can comment on or make changes to this bug.
Description stevenable 2008-04-15 15:51:59 UTC
Product Version: NetBeans IDE 6.0.1 (Build 200801291616)
Java: 1.6.0_05; Java HotSpot(TM) Client VM 10.0-b19
(Was uncertain if this was "binding" or "ui" subcomponent)

Created a form based on JPanel and one based on JFrame.  The panel was then placed within the frame (using copy/paste of
the bean class rather than creating it from palette).  Because these are internal components, I saw no need to make them
public, just package level classes (so go back and remove "public" that wizard added).  After changing access qualifier,
the code builds and runs without error and the panel will display in the designer with no problem.  But the frame gets
an error when going to design mode (error being it could not create the panel component, see error below).  Yet if panel
is declared public (and recompiled), then the frame will display in designer.  

An example of this code is given in the attached project.  Again note the code works fine when built and executed and
the panel alone works fine in the designer when package level but not when part of the frame.  It's even more confusing
in that caching appears to occasionally hold the "prior" version until a NetBeans restart.  This may be a reflection
problem and not part of NetBeans.  [It should be noted the original copy/paste of the panel bean was only allowed when
the panel was public class.] 

The log reports it as a reflection error in form.CreationFactory:
  INFO [org.netbeans.modules.form.BeanSupport]: Cannot create default instance of: pkg.MyPanel
  java.lang.IllegalAccessException: Class org.netbeans.modules.form.CreationFactory can not access a member of class
pkg.MyPanel with modifiers ""
	at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
	at java.lang.Class.newInstance0(Class.java:349)
	at java.lang.Class.newInstance(Class.java:308)
	at org.netbeans.modules.form.CreationFactory.createDefaultInstance(CreationFactory.java:163)
[catch] at org.netbeans.modules.form.BeanSupport.createBeanInstance(BeanSupport.java:81)
	at org.netbeans.modules.form.BeanSupport.getDefaultInstance(BeanSupport.java:107)
... remainder removed ...
Comment 1 stevenable 2008-04-15 15:53:51 UTC
Created attachment 60214 [details]
Zip containing example project demonstrating the problem
Comment 2 Jan Stola 2008-05-29 15:51:03 UTC
This is a known feature of Java GUI builders. They are based on JavaBeans specification e.g. can work with 
beans/components that are public and have public no-argument constructor.

On the other hand, I understand that in some cases (like your one) it would help to be able to use non-public classes. 
Unfortunately, it would require bigger changes across the GUI builder, because by now it expects public classes only. 
This support would also require implementation of some additional checks e.g. whether the given non-public class can be 
added into this form etc.

Keeping this issue as an enhancement request. Let's see whether we will have resources to implement it in future.