NullPointerException when call saveData

I start a transaction, create some entries in some foundsets and set some data then call saveData and commit, but on saveData I get this:

org.mozilla.javascript.WrappedException: Wrapped java.lang.NullPointerException (/Users/bogdan/work/workspace_servoy/AeroPlusCommons/globals.js#2132)
	at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1828)
	at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:199)
	at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:353)
	at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3666)
	at script.databaseSaveData(/Users/bogdan/work/workspace_servoy/AeroPlusCommons/globals.js:2132)
	at script.databaseCommit(/Users/bogdan/work/workspace_servoy/AeroPlusCommons/globals.js:2077)
	at script.generateInvoices(/Users/bogdan/work/workspace_servoy/AeroPlus/forms/owner_invoice_entries_not_billed.js:165)
	at script.onSave(/Users/bogdan/work/workspace_servoy/AeroPlus/forms/owner_invoice_entries_not_billed_generate.js:52)
	at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2680)
	at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:166)
	at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:387)
	at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3135)
	at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:165)
	at com.servoy.j2db.scripting.ScriptEngine.executeFunction(ScriptEngine.java:476)
	at com.servoy.j2db.debug.RemoteDebugScriptEngine.executeFunction(RemoteDebugScriptEngine.java:382)
	at com.servoy.j2db.FormController.executeFunction(FormController.java:3977)
	at com.servoy.j2db.FormController.executeFunction(FormController.java:3865)
	at com.servoy.j2db.FormController.executeFunction(FormController.java:3787)
	at com.servoy.j2db.FormController$ScriptExecuter.executeFunction(FormController.java:3642)
	at com.servoy.j2db.ui.BaseEventExecutor.fireEventCommand(BaseEventExecutor.java:272)
	at com.servoy.j2db.ui.BaseEventExecutor.fireActionCommand(BaseEventExecutor.java:217)
	at com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor.onEvent(WebEventExecutor.java:364)
	at com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor$2.onEvent(WebEventExecutor.java:168)
	at org.apache.wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:177)
	at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:302)
	at org.apache.wicket.request.target.component.listener.BehaviorRequestTarget.processEvents(BehaviorRequestTarget.java:157)
	at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
	at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
	at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
	at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1436)
	at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
	at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:486)
	at com.servoy.j2db.server.servlets.Zl.doGet(Zl.java:4)
	at org.apache.wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:138)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:567)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
	at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.NullPointerException
	at com.servoy.j2db.server.headlessclient.dataui.FoundsetRecordItemModel.<init>(WebCellBasedView.java:3448)
	at com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView$WebCellBasedViewListView.getListItemModel(WebCellBasedView.java:618)
	at com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView.tableChanged(WebCellBasedView.java:1842)
	at com.servoy.j2db.dataprocessing.TableAndListEventDelegate.fireTableModelEvent(TableAndListEventDelegate.java:75)
	at com.servoy.j2db.dataprocessing.TableAndListEventDelegate$1.run(TableAndListEventDelegate.java:168)
	at com.servoy.j2db.dataprocessing.TableAndListEventDelegate.fireTableAndListEvent(TableAndListEventDelegate.java:175)
	at com.servoy.j2db.dataprocessing.SwingRelatedFoundSet.fireFoundSetEvent(SwingRelatedFoundSet.java:159)
	at com.servoy.j2db.dataprocessing.EditRecordList.fireEvents(EditRecordList.java:1097)
	at com.servoy.j2db.dataprocessing.EditRecordList.stopEditing(EditRecordList.java:661)
	at com.servoy.j2db.dataprocessing.EditRecordList.stopEditing(EditRecordList.java:178)
	at com.servoy.j2db.dataprocessing.EditRecordList.stopEditing(EditRecordList.java:166)
	at com.servoy.j2db.dataprocessing.JSDatabaseManager.js_saveData(JSDatabaseManager.java:1733)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:179)
	... 43 more

What could be the cause? I can’t see what I’m doing wrong…

Just tried something else, almost same error.

org.mozilla.javascript.WrappedException: Wrapped java.lang.NullPointerException (/Users/bogdan/work/workspace_servoy/AeroPlus/forms/owner_invoice_entries_not_billed.js#144)
	at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1828)
	at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:199)
	at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:353)
	at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3666)
	at script.generateInvoices(/Users/bogdan/work/workspace_servoy/AeroPlus/forms/owner_invoice_entries_not_billed.js:144)
	at script.onSave(/Users/bogdan/work/workspace_servoy/AeroPlus/forms/owner_invoice_entries_not_billed_generate.js:54)
	at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2680)
	at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:166)
	at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:387)
	at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3135)
	at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:165)
	at com.servoy.j2db.scripting.ScriptEngine.executeFunction(ScriptEngine.java:476)
	at com.servoy.j2db.debug.RemoteDebugScriptEngine.executeFunction(RemoteDebugScriptEngine.java:382)
	at com.servoy.j2db.FormController.executeFunction(FormController.java:3977)
	at com.servoy.j2db.FormController.executeFunction(FormController.java:3865)
	at com.servoy.j2db.FormController.executeFunction(FormController.java:3787)
	at com.servoy.j2db.FormController$ScriptExecuter.executeFunction(FormController.java:3642)
	at com.servoy.j2db.ui.BaseEventExecutor.fireEventCommand(BaseEventExecutor.java:272)
	at com.servoy.j2db.ui.BaseEventExecutor.fireActionCommand(BaseEventExecutor.java:217)
	at com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor.onEvent(WebEventExecutor.java:364)
	at com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor$2.onEvent(WebEventExecutor.java:168)
	at org.apache.wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:177)
	at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:302)
	at org.apache.wicket.request.target.component.listener.BehaviorRequestTarget.processEvents(BehaviorRequestTarget.java:157)
	at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
	at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
	at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
	at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1436)
	at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
	at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:486)
	at com.servoy.j2db.server.servlets.Zl.doGet(Zl.java:4)
	at org.apache.wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:138)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:567)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
	at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.NullPointerException
	at com.servoy.j2db.server.headlessclient.dataui.FoundsetRecordItemModel.<init>(WebCellBasedView.java:3448)
	at com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView$WebCellBasedViewListView.getListItemModel(WebCellBasedView.java:618)
	at com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView.tableChanged(WebCellBasedView.java:1842)
	at com.servoy.j2db.dataprocessing.TableAndListEventDelegate.fireTableModelEvent(TableAndListEventDelegate.java:75)
	at com.servoy.j2db.dataprocessing.TableAndListEventDelegate$1.run(TableAndListEventDelegate.java:168)
	at com.servoy.j2db.dataprocessing.TableAndListEventDelegate.fireTableAndListEvent(TableAndListEventDelegate.java:175)
	at com.servoy.j2db.dataprocessing.SwingRelatedFoundSet.fireFoundSetEvent(SwingRelatedFoundSet.java:159)
	at com.servoy.j2db.dataprocessing.EditRecordList.fireEvents(EditRecordList.java:1097)
	at com.servoy.j2db.dataprocessing.EditRecordList.stopEditing(EditRecordList.java:661)
	at com.servoy.j2db.dataprocessing.EditRecordList.stopEditing(EditRecordList.java:178)
	at com.servoy.j2db.dataprocessing.JSDatabaseManager.js_saveData(JSDatabaseManager.java:1731)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:179)
	... 43 more

Which version of Servoy are you using?

Hi! 5.2.9

What’s strange is that the same piece of code was running for months without any problem. And suddenly, when testing using the developer this error came up.

I moved saveData into different places in the code, and I saw that the exception is raised just after I set a field of a record. That field is used inside a relation the foundset is based on. Setting it with another value might remove the record from the foundset, because it doesn’t meet the relation’s condition anymore. Still, this code was running fine so far. Didn’t change anything and got the error.

There is a fix in 5.2.10 for this. Can you try 5.2.10?
Was there no recent change in your code’s behavior that uncovered this exception? Which previous version worked as expected with this same solution?

I did no change to the functionality that could affect this. I changed something in that function but is not related with setting that value on the field the relation is counting on. I’ll have another look on the revisions to be sure, although I’m sure about.

The online server is using 5.2.10 for … I think 2 months or so. Before that it was 5.2.9 as well as my current developer where I noticed the exception. I wrote that piece of code more then a year ago. But I don’t remember when I start using transactions on it, although the exception is when saveData is called. But I never saw the error before. And online it never appeared, otherwise the users would have noticed bad behavior, because that function generate invoices for the clients of our clients :) and involves money, and they run that at least once per month, so they would have noticed immediately. But we never got a complain about.