Dealing with a NullReference Exception encountered using a when JavaAction from the Marketplace JSON Structure module.

0
I'm trying to export a list of System.FileDocument objects into a JSON structure using the following marketplace module: Mendix Marketplace - JSON Structure. However, I am encountering a null pointer exception (on line 50) in the JavaAction `ExportList`. I followed the documentation for this module and am certain that the value that is being passed into the ExportList JavaAction contains non null objects.   The file objects I am attempting to pass definitely exist as I've been able to save them to Amazon S3 without any issue. I have also tried doing this with just a list of entities containing a single string to no avail.   I cant find the com.mendix imports found in the java code below anywhere locally but I suspect thats not the issue since the error is unrelated to them.   The code in the JavaAction where the error occurs at line 50 ( .peek(jsonObject -> jsonObject.setOrder(SortNumberProvider.next())) ): // This file was generated by Mendix Studio Pro. // // WARNING: Only the following code will be retained when actions are regenerated: // - the import list // - the code between BEGIN USER CODE and END USER CODE // - the code between BEGIN EXTRA CODE and END EXTRA CODE // Other code you write will be lost the next time you deploy the project. // Special characters, e.g., é, ö, à, etc. are supported in comments. package jsonstructure.actions; import com.mendix.systemwideinterfaces.core.IContext; import com.mendix.webui.CustomJavaAction; import com.mendix.systemwideinterfaces.core.IMendixObject; import jsonstructure.export.MendixObjectExporter; import jsonstructure.export.SortNumberProvider; import jsonstructure.proxies.JSONArray; /** * Export a list of any entity to a generic JSON array. * There must be an export microflow defined for the entity that is being exported. */ public class ExportList extends CustomJavaAction<IMendixObject> { private java.util.List<IMendixObject> Input; private java.lang.String PrefixOverride; public ExportList(IContext context, java.util.List<IMendixObject> Input, java.lang.String PrefixOverride) { super(context); this.Input = Input; this.PrefixOverride = PrefixOverride; } @java.lang.Override public IMendixObject executeAction() throws Exception { // BEGIN USER CODE if (this.Input == null) return null; MendixObjectExporter mendixObjectExporter = new MendixObjectExporter(getContext()); if (this.PrefixOverride != null) mendixObjectExporter.withMicroflowPrefix(this.PrefixOverride); JSONArray jsonArray = new JSONArray(getContext()); this.Input.stream() .map(mendixObjectExporter::exportMendixObject) .peek(jsonObject -> jsonObject.setOrder(SortNumberProvider.next())) .forEach(jsonObject -> jsonObject.setarray_items(jsonArray)); return jsonArray.getMendixObject(); // END USER CODE } /** * Returns a string representation of this action * @return a string representation of this action */ @java.lang.Override public java.lang.String toString() { return "ExportList"; } // BEGIN EXTRA CODE // END EXTRA CODE }   The error I'm getting (Note: there are no errors if the list is empty): com.mendix.webui.WebUIException: Exception while executing runtime operation at com.mendix.webui.actions.client.RuntimeOperationAction.$anonfun$apply$1(RuntimeOperationAction.scala:60) Caused by: com.mendix.modules.microflowengine.MicroflowException: com.mendix.systemwideinterfaces.MendixRuntimeException: java.lang.NullPointerException at CubicleQrManagement.JSONExport_CubicleFiles (JavaAction : 'Export list') at CubicleQrManagement.generateCubicleJson (SubMicroflow : 'JSONExport_CubicleFiles') at CubicleQrManagement.saveCubicleConfiguration (SubMicroflow : 'generateCubicleJson') Advanced stacktrace: at com.mendix.modules.microflowengine.MicroflowUtil.processException(MicroflowUtil.java:83) Caused by: com.mendix.core.CoreRuntimeException: com.mendix.systemwideinterfaces.MendixRuntimeException: java.lang.NullPointerException at com.mendix.basis.actionmanagement.ActionManager.executeSync(ActionManager.scala:110) Caused by: com.mendix.systemwideinterfaces.MendixRuntimeException: java.lang.NullPointerException at com.mendix.util.classloading.Runner$.withContextClassLoader(Runner.scala:23) Caused by: java.lang.NullPointerException: null at jsonstructure.actions.ExportList.lambda$executeAction$0(ExportList.java:50) at java.base/java.util.stream.ReferencePipeline$11$1.accept(ReferencePipeline.java:441) at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655) at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497) at jsonstructure.actions.ExportList.executeAction(ExportList.java:51) at jsonstructure.actions.ExportList.executeAction(ExportList.java:23) at com.mendix.systemwideinterfaces.core.UserAction.execute(UserAction.java:58) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.doCall(CoreActionHandlerImpl.scala:71) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.call(CoreActionHandlerImpl.scala:48) at com.mendix.core.actionmanagement.internal.InternalCoreAction.call(InternalCoreAction.java:57) at com.mendix.basis.actionmanagement.ActionManager.$anonfun$executeSync$2(ActionManager.scala:106) at com.mendix.util.classloading.Runner$.withContextClassLoader(Runner.scala:20) at com.mendix.basis.actionmanagement.ActionManager.executeSync(ActionManager.scala:105) at com.mendix.basis.actionmanagement.UserActionCallBuilderImpl.execute(UserActionCallBuilderImpl.scala:57) at com.mendix.modules.microflowengine.actions.actioncall.ForegroundJavaAction.doExecute(ForegroundJavaAction.scala:35) at com.mendix.modules.microflowengine.actions.actioncall.ForegroundJavaAction.doExecute(ForegroundJavaAction.scala:11) at com.mendix.modules.microflowengine.actions.actioncall.JavaAction.execute(JavaAction.scala:38) at com.mendix.modules.microflowengine.microflow.impl.MicroflowObject.$anonfun$execute$1(MicroflowObject.scala:32) at scala.Option.flatMap(Option.scala:283) at com.mendix.modules.microflowengine.microflow.impl.MicroflowObject.execute(MicroflowObject.scala:29) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.$anonfun$executeAfterBreakingIfNecessary$2(MicroflowImpl.scala:167) at scala.Option.flatMap(Option.scala:283) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAfterBreakingIfNecessary(MicroflowImpl.scala:167) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAction(MicroflowImpl.scala:114) at com.mendix.systemwideinterfaces.core.UserAction.execute(UserAction.java:58) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.doCall(CoreActionHandlerImpl.scala:71) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.call(CoreActionHandlerImpl.scala:48) at com.mendix.core.actionmanagement.internal.InternalCoreAction.call(InternalCoreAction.java:57) at com.mendix.basis.actionmanagement.ActionManager.$anonfun$executeSync$2(ActionManager.scala:106) at com.mendix.util.classloading.Runner$.withContextClassLoader(Runner.scala:20) at com.mendix.basis.actionmanagement.ActionManager.executeSync(ActionManager.scala:105) at com.mendix.basis.component.ExecutionCore.doExecuteSync(ExecutionCore.scala:148) at com.mendix.basis.component.ExecutionCore.doExecuteSync$(ExecutionCore.scala:147) at com.mendix.basis.component.InternalCore.doExecuteSync(InternalCore.scala:24) at com.mendix.basis.component.ExecutionCore.executeSync(ExecutionCore.scala:97) at com.mendix.basis.component.ExecutionCore.executeSync$(ExecutionCore.scala:94) at com.mendix.basis.component.InternalCore.executeSync(InternalCore.scala:24) at com.mendix.modules.microflowengine.MicroflowExecuter$.executeSync(MicroflowExecuter.scala:19) at com.mendix.modules.microflowengine.actions.SubMicroflowAction.execute(SubMicroflowAction.scala:37) at com.mendix.modules.microflowengine.microflow.impl.MicroflowObject.$anonfun$execute$1(MicroflowObject.scala:32) at scala.Option.flatMap(Option.scala:283) at com.mendix.modules.microflowengine.microflow.impl.MicroflowObject.execute(MicroflowObject.scala:29) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.$anonfun$executeAfterBreakingIfNecessary$2(MicroflowImpl.scala:167) at scala.Option.flatMap(Option.scala:283) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAfterBreakingIfNecessary(MicroflowImpl.scala:167) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAction(MicroflowImpl.scala:114) at com.mendix.systemwideinterfaces.core.UserAction.execute(UserAction.java:58) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.doCall(CoreActionHandlerImpl.scala:71) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.call(CoreActionHandlerImpl.scala:48) at com.mendix.core.actionmanagement.internal.InternalCoreAction.call(InternalCoreAction.java:57) at com.mendix.basis.actionmanagement.ActionManager.$anonfun$executeSync$2(ActionManager.scala:106) at com.mendix.util.classloading.Runner$.withContextClassLoader(Runner.scala:20) at com.mendix.basis.actionmanagement.ActionManager.executeSync(ActionManager.scala:105) at com.mendix.basis.component.ExecutionCore.doExecuteSync(ExecutionCore.scala:148) at com.mendix.basis.component.ExecutionCore.doExecuteSync$(ExecutionCore.scala:147) at com.mendix.basis.component.InternalCore.doExecuteSync(InternalCore.scala:24) at com.mendix.basis.component.ExecutionCore.executeSync(ExecutionCore.scala:97) at com.mendix.basis.component.ExecutionCore.executeSync$(ExecutionCore.scala:94) at com.mendix.basis.component.InternalCore.executeSync(InternalCore.scala:24) at com.mendix.modules.microflowengine.MicroflowExecuter$.executeSync(MicroflowExecuter.scala:19) at com.mendix.modules.microflowengine.actions.SubMicroflowAction.execute(SubMicroflowAction.scala:37) at com.mendix.modules.microflowengine.microflow.impl.MicroflowObject.$anonfun$execute$1(MicroflowObject.scala:32) at scala.Option.flatMap(Option.scala:283) at com.mendix.modules.microflowengine.microflow.impl.MicroflowObject.execute(MicroflowObject.scala:29) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.$anonfun$executeAfterBreakingIfNecessary$2(MicroflowImpl.scala:167) at scala.Option.flatMap(Option.scala:283) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAfterBreakingIfNecessary(MicroflowImpl.scala:167) at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAction(MicroflowImpl.scala:114) at com.mendix.systemwideinterfaces.core.UserAction.execute(UserAction.java:58) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.doCall(CoreActionHandlerImpl.scala:71) at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.call(CoreActionHandlerImpl.scala:48) at com.mendix.core.actionmanagement.internal.InternalCoreAction.call(InternalCoreAction.java:57) at com.mendix.basis.actionmanagement.ActionManager.$anonfun$executeSync$2(ActionManager.scala:106) at com.mendix.util.classloading.Runner$.withContextClassLoader(Runner.scala:20) at com.mendix.basis.actionmanagement.ActionManager.executeSync(ActionManager.scala:105) at com.mendix.basis.actionmanagement.MicroflowCallBuilderImpl.execute(MicroflowCallBuilderImpl.scala:62) at com.mendix.webui.actions.client.MicroflowRuntimeOperationExecutor.runMicroflow(MicroflowRuntimeOperationExecutor.scala:97) at com.mendix.webui.actions.client.MicroflowRuntimeOperationExecutor.$anonfun$apply$5(MicroflowRuntimeOperationExecutor.scala:57) at com.mendix.webui.actions.client.RegularClientAction$Helpers$.$anonfun$liftEither$1(RegularClientAction.scala:30) at com.mendix.webui.actions.client.RegularClientAction$Helpers$StateHandler.$anonfun$apply$4(RegularClientAction.scala:56) at com.mendix.webui.requesthandling.helpers.StateHandling.withState(StateHandling.scala:46) at com.mendix.webui.requesthandling.helpers.StateHandling.withState$(StateHandling.scala:43) at com.mendix.webui.actions.client.RegularClientAction$Helpers$StateHandler.withState(RegularClientAction.scala:46) at com.mendix.webui.actions.client.RegularClientAction$Helpers$StateHandler.apply(RegularClientAction.scala:54) at com.mendix.webui.actions.client.RegularClientAction$Helpers$StateHandler.apply(RegularClientAction.scala:46) at com.mendix.webui.actions.client.MicroflowRuntimeOperationExecutor.apply(MicroflowRuntimeOperationExecutor.scala:58) at com.mendix.webui.actions.client.RuntimeOperationAction.$anonfun$apply$1(RuntimeOperationAction.scala:55) at scala.util.Either.flatMap(Either.scala:352) at com.mendix.webui.actions.client.RuntimeOperationAction.apply(RuntimeOperationAction.scala:41) at com.mendix.webui.actions.client.RuntimeOperationAction.apply(RuntimeOperationAction.scala:30) at com.mendix.webui.actions.client.RegularClientAction$Helpers$.$anonfun$liftEither$1(RegularClientAction.scala:30) at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$3(RegularClientAction.scala:120) at scala.util.Try$.apply(Try.scala:210) at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$2(RegularClientAction.scala:120) at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$2$adapted(RegularClientAction.scala:118) at com.mendix.webui.requesthandling.helpers.ContextHandling.$anonfun$inContext$7(ContextHandling.scala:58) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18) at com.mendix.basis.actionmanagement.ActionMonitoring$.$anonfun$monitor$1(ActionMonitoring.scala:52) at com.mendix.util.classloading.Runner$.withContextClassLoader(Runner.scala:20) at com.mendix.basis.actionmanagement.ActionMonitoring$.monitor(ActionMonitoring.scala:52) at com.mendix.webui.requesthandling.helpers.ContextHandling.inContext(ContextHandling.scala:58) at com.mendix.webui.requesthandling.helpers.ContextHandling.inContext$(ContextHandling.scala:32) at com.mendix.webui.actions.client.RegularClientAction.inContext(RegularClientAction.scala:94) at com.mendix.webui.requesthandling.helpers.ContextHandling.inContext(ContextHandling.scala:29) at com.mendix.webui.requesthandling.helpers.ContextHandling.inContext$(ContextHandling.scala:21) at com.mendix.webui.actions.client.RegularClientAction.inContext(RegularClientAction.scala:94) at com.mendix.webui.actions.client.RegularClientAction.$anonfun$execute$1(RegularClientAction.scala:118) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18) at com.mendix.webui.requesthandling.helpers.ProfileHandling.profileRequest(ProfileHandling.scala:14) at com.mendix.webui.requesthandling.helpers.ProfileHandling.profileRequest$(ProfileHandling.scala:10) at com.mendix.webui.actions.client.RegularClientAction.profileRequest(RegularClientAction.scala:94) at com.mendix.webui.actions.client.RegularClientAction.execute(RegularClientAction.scala:115) at com.mendix.webui.requesthandling.ClientRequestHandler.handleAction(ClientRequestHandler.scala:105) at com.mendix.webui.requesthandling.ClientRequestHandler.processRequest(ClientRequestHandler.scala:78) at com.mendix.externalinterface.connector.RequestHandler.doProcessRequest(RequestHandler.java:37) at com.mendix.external.connector.MxRuntimeConnector.$anonfun$processRequest$1(MxRuntimeConnector.scala:54) at com.mendix.external.connector.MxRuntimeConnector.$anonfun$processRequest$1$adapted(MxRuntimeConnector.scala:54) at com.mendix.util.classloading.Runner$.withContextClassLoader(Runner.scala:20) at com.mendix.external.connector.MxRuntimeConnector.processRequest(MxRuntimeConnector.scala:54) at com.mendix.basis.impl.MxRuntimeImpl.processRequest(MxRuntimeImpl.scala:221) at com.mendix.m2ee.appcontainer.server.handler.RuntimeServlet.service(RuntimeServlet.scala:40) at javax.servlet.http.HttpServlet.service(HttpServlet.java:750) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764) at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1665) at org.eclipse.jetty.websocket.servlet.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:170) at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202) at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1635) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:527) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1570) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1385) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:484) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1543) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1307) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122) at org.eclipse.jetty.server.Server.handle(Server.java:563) at org.eclipse.jetty.server.HttpChannel.lambda$handle$0(HttpChannel.java:505) at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:762) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:497) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:282) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:314) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100) at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53) at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:416) at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:385) at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:272) at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.lambda$new$0(AdaptiveExecutionStrategy.java:140) at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:411) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:936) at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1080) at java.base/java.lang.Thread.run(Thread.java:829)   The microflow and where the error occurs:   Any input would be greatly appreciated.
asked
2 answers
0

A nullpointer means that something is not there that should be there. Now I am not sure if filedocuments are supported in this module. Did you try without the file documents?

And if you need to pass the contents of a file document I would base64 encode those to strings and use those strings in your JSON. You could use a unlimited string temp object and thus create from the filedocuments a list of temp objects containing the base64 strings and use that as source for the JSON export list.

 

Regards,

Ronald

 

answered
0

look like this have null item before go to peek .map(mendixObjectExporter::exportMendixObject)

you may need to filter the null value 

         

this.Input.stream()
    .map(mendixObjectExporter::exportMendixObject)
    .filter(Objects::nonNull) // Filter out null values
    .peek(jsonObject -> jsonObject.setOrder(SortNumberProvider.next()))
    .forEach(jsonObject -> jsonObject.setarray_items(jsonArray));

Hope this help.

answered