Null Pointer Exception during init method of groovy scripts

User c1ce6b3d19

30-10-2012 23:44:29

I've been getting NPEs on code during init calls fo groovy button scripts.


...



init = { widget ->  //line 34


    def rs = widget.form.resultSet  //line35


    def dataTree = rs.dataTree  //line 36



...


When I open the form, I get an NPE.  



java.lang.NullPointerException: Cannot get property 'resultSet' on null object


at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:56)


at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:156)


at org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:44)


at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:227)


at script1351639868222387238318$_run_closure1.doCall(script1351639868222387238318.groovy:35)



 


Of course, this kills the rest of the operation (i.e. evaluate method) of the button.  Is there a race condition where the initialization of the button occurs before the form is initialized?  What should I do about it?


 


Jon

ChemAxon 2bdd02d1e5

31-10-2012 10:26:05

Hi Jon


Yes, the widget is created before the form is initialized. This does not affect evaluate method in my simple button script. It just did not continue with the init method...but still runs a code in evaluate section when clicking to button.


We are fixing this for 5.12 (maybe 5.11.4 depending on how the fix is going to look like).


I assume that you want to run a script right after the form is initialized. There is probably no workaround for this.


Thanks for letting us know.


Filip

ChemAxon 2bdd02d1e5

13-11-2012 16:59:08

This is fixed in IJC 5.11.4 which is going out pretty soon.


Cheers!
Filip 

User c1ce6b3d19

14-11-2012 01:38:35

Thanks Filip.  So, how will it work in the new release?  Is the button's init method called after the initialization of the form.  I'll try it out when it is released.  


Is the init method called every time you open a form, or just the first time?  Is the destroy method called every time you close a form, or just the first time?


When using the destroy method are there limitations (such as missing resources like result sets or data trees)?  


(My apologies if it is already in the documentation, but I couldn't find it).


Jon

ChemAxon 99d87cf303

14-11-2012 15:32:34

Hi Jon,


It turned out destroy method is not called at all. It was fixed in development version just now and will work correctly in the IJC 5.11.4 as well.


The intended semantics are:



In both cases resources, like result set, are ready and can be used at the time of method call.


We will ensure it is properly documented on the website.


Thanks for the feedback.
- Martin