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 181997 - Failed to write value to Property "sampleProperty" when JavaBean references a static variable in container
Summary: Failed to write value to Property "sampleProperty" when JavaBean references a...
Status: RESOLVED INVALID
Alias: None
Product: guibuilder
Classification: Unclassified
Component: App Framework (show other bugs)
Version: 6.x
Hardware: All All
: P3 normal (vote)
Assignee: issues@guibuilder
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-14 23:02 UTC by dimo
Modified: 2011-11-16 16:41 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
sample project showing problem (17.50 KB, application/octet-stream)
2010-03-14 23:02 UTC, dimo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description dimo 2010-03-14 23:02:31 UTC
Created attachment 95142 [details]
sample project showing problem

I've been able to replicate this at will. Basically what I did was create a bean and then added it to a container JPanel form several times. In the setProperty() function I reference a static array in the container to keep track of the beans that have been added to the form dynamically (this way I could loop through the beans programmatically and do something if need be). Anyhow the problem appears when after I've tidied up my form I try to access any of the properties of the beans. I get the following error:
Failed to Write the Value to the property "SampleProperty".

This also seems to be related to the "Form Loaded with Errors" (It seems that when I first made my bean it did not reference the static array and so the IDE allowed me to set the properties for the bean, the next time around when I had added the reference to the static method something broker and when the IDE tries to load the saved property values it seems to be stepping on itself. 

Attached is a sample project that is likely to give the same error on your end.

I've also noticed that the build and clean doesn't always really clean and I have to delete the class folder to really see if my changes make a difference.

Hope this can be fixed, Thanks.
Comment 1 Jan Stola 2010-03-16 11:08:03 UTC
The value of the 'sampleProperty' cannot be set because it throws NullPointerException. NewBean.setSampleProperty() calls NewJPanel.getNewBeans().add(this). Unfortunately, NewJPanel.getNewBeans() returns null because the corresponding field NewJPanel.NewBeans is not initialized, i.e., the property cannot be set because of bug in your code. It has nothing to do with NetBeans.

If you are able to reproduce problems with cleaning/building of the project then, please, report it against java/Project. I also saw these problems, but I am not able to reproduce them reliably. At least, it seems that separate 'Clean' and 'Build' actions are more reliable than 'Clean and Build' action.
Comment 2 dimo 2010-03-16 22:13:55 UTC
Thanks Jan for yor follow-up. I'm not sure I understand you correctly, the error I'm getting is from the IDE when I switch to design view for the adorning JPanel, not during run-time, the log file attached is also from netbeans not the runtime stack. I'm new to javabeans so perhaps I'm just not standing on steady grounds. I suppose what you are telling me is that the IDE dynamically leverages the uncompiled code to interact with the bean? I'm a little confused here, I would greatly appreciate your elaboration. Actually, could you open up the project I attached in netbeans, open the NewJPanel in design view, right-click the bean on the panel, choose properties and try to change the value of the property, Netbeans should then give you the same error I reported.
Cheers,
dimo
Comment 3 dimo 2010-03-16 22:16:02 UTC
Thanks Jan for yor follow-up. I'm not sure I understand you correctly, the
error I'm getting is from the IDE when I switch to design view for the adorning
JPanel, not during run-time, the log file attached is also from netbeans not
the runtime stack. I'm new to javabeans so perhaps I'm just not standing on
steady grounds. I suppose what you are telling me is that the IDE dynamically
leverages the uncompiled code to interact with the bean? I'm a little confused
here, I would greatly appreciate your elaboration. Actually, could you open up
the project I attached in netbeans, open the NewJPanel in design view,
right-click the bean on the panel, choose properties and try to change the
value of the property, Netbeans should then give you the same error I reported.
Cheers,
dimo

(In reply to comment #1)
> The value of the 'sampleProperty' cannot be set because it throws
> NullPointerException. NewBean.setSampleProperty() calls
> NewJPanel.getNewBeans().add(this). Unfortunately, NewJPanel.getNewBeans()
> returns null because the corresponding field NewJPanel.NewBeans is not
> initialized, i.e., the property cannot be set because of bug in your code. It
> has nothing to do with NetBeans.
> If you are able to reproduce problems with cleaning/building of the project
> then, please, report it against java/Project. I also saw these problems, but I
> am not able to reproduce them reliably. At least, it seems that separate
> 'Clean' and 'Build' actions are more reliable than 'Clean and Build' action.
Comment 4 Jan Stola 2010-03-17 09:50:04 UTC
> Actually, could you open up the project I attached in netbeans,
> open the NewJPanel in design view, right-click the bean on
> the panel, choose properties and try to change the value of
> the property, Netbeans should then give you the same error I reported.

Of course, I did that before. I was able to reproduce the described problem and I explained it in my previous comment.

> I suppose what you are telling me is that the IDE dynamically
> leverages the uncompiled code to interact with the bean?
> I'm a little confused here, I would greatly appreciate your elaboration.

The GUI Builder uses the compiled code of your bean (and all referenced classes of your bean).
- when the project is build then NewBean.class and NewJPanel.class (corresponding to the actual version of sources) are created
- when you add NewBean into NewJPanel (or when you open NewJPanel with NewBean already added) then a new instance of NewBean is created in IDE (at design time)
- when you set sampleProperty of NewBean then the value of this property is set in the mentioned instance (at design time/in IDE), i.e., NewBean.setSampleProperty() is invoked
- NewBean.setSampleProperty() calls NewJPanel.getNewBeans().add(this); This calls forces loading of NewJPanel class (from the last NewJPanel.class file created during compilation) into the IDE
- the mentioned call throws NullPointerException because NewJPanel.NewBeans static field dereferenced by this call is null, i.e., is not initialized

This is a problem of your code (not NetBeans code). You can fix it easily. Just replace
public static ArrayList<NewBean> NewBeans;
in NewJPanel by
public static ArrayList<NewBean> NewBeans = new ArrayList<NewBean>();
close NewJPanel, clean your project, build your project, reopen NewJPanel.
Comment 5 dimo 2010-03-17 22:19:29 UTC
Jan,
   Thank you dearly for your support. Your suggestion did fix the problem. 
However, although I did forget to instantiate the arraylist in the example I sent you, in my development project where I was having this problem, I had instantiated the Arraylist in the constructor instead of in the class member field declaration as you suggested, I guess the constructor is not called when the form class is loaded by the IDE? 

When I add the initialization to the constructor of the example I sent, I still get an error. Only if I initialize the member field explicitly in the declaration does the error go away. 

In any case, thank you, I appreciate your help very much.

Cheers,
dimo