1 2 Previous Next 19 Replies Latest reply on Apr 26, 2014 4:31 AM by 其凡 莫

    getProcess in ProcessInstanceImpl throws a NullPointerException

    joploya Newbie



      I have a NullPointerException when I set process variables and I don't know if it is normal.


      The exception comes from this code of jbpm :


         //In ProcessInstanceImpl
         public Process getProcess() {
              if (this.process == null) {
                  this.process = kruntime.getKnowledgeBase().getProcess(processId);
              return this.process;


      and this is the StackTrace :


      SEVERE [javax.faces.event] (http-- java.lang.NullPointerException
                at org.jbpm.process.instance.impl.ProcessInstanceImpl.getProcess(ProcessInstanceImpl.java:68)
                at org.jbpm.process.instance.impl.ProcessInstanceImpl.getContextInstance(ProcessInstanceImpl.java:133)
                at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.setVariable(WorkflowProcessInstanceImpl.java:238)
                at com.st.ams.task.management.TaskManager.setProcessVariable(TaskManager.java:234)
                at com.st.ams.task.management.TaskManager$Proxy$_$$_WeldClientProxy.setProcessVariable(TaskManager$Proxy$_$$_WeldClientProxy.java)
                at com.st.ams.form.nfg.jbpm.process.NewFinishedGoodProcessManagement.manageInstanceFgPlanStep2(NewFinishedGoodProcessManagement.java:149)
                at com.st.ams.form.nfg.jbpm.process.NewFinishedGoodProcessManagement.manageInstancePlan(NewFinishedGoodProcessManagement.java:89)
                at com.st.ams.form.nfg.jbpm.process.NewFinishedGoodProcessManagement.manageInstance(NewFinishedGoodProcessManagement.java:71)
                at com.st.ams.form.nfg.jbpm.process.NewFinishedGoodProcessManagement$Proxy$_$$_WeldClientProxy.manageInstance(NewFinishedGoodProcessManagement$Proxy$_$$_WeldClientProxy.java)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:264)
                at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52)
                at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:137)
                at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:260)
                at org.jboss.weld.introspector.jlr.WeldMethodImpl.invokeOnInstance(WeldMethodImpl.java:170)
                at org.jboss.weld.introspector.ForwardingWeldMethod.invokeOnInstance(ForwardingWeldMethod.java:51)
                at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:154)
                at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:241)
                at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:229)
                at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:207)
                at org.jboss.weld.manager.BeanManagerImpl.notifyObservers(BeanManagerImpl.java:569)
                at org.jboss.weld.manager.BeanManagerImpl.fireEvent(BeanManagerImpl.java:564)
                at org.jboss.weld.event.EventImpl.fire(EventImpl.java:68)
                at com.st.ams.form.bean.EmailBean.send(EmailBean.java:148)
                at com.st.ams.form.bean.EmailBean$Proxy$_$$_WeldClientProxy.send(EmailBean$Proxy$_$$_WeldClientProxy.java)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
                at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
                at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:39)
                at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
                at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:153)
                at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
                at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
                at javax.faces.component.UICommand.broadcast(UICommand.java:300)
                at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
                at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
                at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
                at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
                at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
                at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
                at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
                at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
                at org.jboss.solder.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:65)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
                at org.jboss.solder.servlet.event.ServletEventBridgeFilter.doFilter(ServletEventBridgeFilter.java:74)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
                at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
                at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:397)
                at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)
                at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
                at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
                at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
                at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
                at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
                at java.lang.Thread.run(Thread.java:722)
       WARN  [org.jboss.solder.exception.control.log] (http-- No handlers found for exception javax.faces.event.AbortProcessingException: java.lang.NullPointerException


      I use persistent session and

      WorkflowProcessInstance wpi = (WorkflowProcessInstance)kSession.getProcessInstance(processInstanceId);

      return a non null instance.



        • 1. Re: getProcess in ProcessInstanceImpl throws a NullPointerException
          bird86 Newbie



          it is used to get Process definition by the attribute 'id' of the element 'process' in *.bpmn file, not processId(ksession.startProcess('').getId()).

          • 2. Re: getProcess in ProcessInstanceImpl throws a NullPointerException
            joploya Newbie

            Sorry but I don't understand your answer.


            I recurrently throws this error when I work with WorkflowProcessInstance.


            This is the code that failed :


            WorkflowProcessInstance wpi = (WorkflowProcessInstance)kSession.getProcessInstance(processInstanceId);
            wpi.setVariable(key, object);




             WorkflowProcessInstance wpi = (WorkflowProcessInstance)kSession.getProcessInstance(processInstanceId);
                                if((wpi == null) || (wpi.getVariable(key) == null)){
                   //This case never appears because of persistent sessions
                                               System.out.println("workflow process instance is null :-(");
                                               System.out.println("workflow process instance is NOT null :-)");
                                               retObj = wpi.getVariable(key);
                                               //node info
                                               System.out.println("list of node instance : ");
                                               for(NodeInstance iNode : wpi.getNodeInstances()){
                         Node node = iNode.getNode();
            • 3. Re: getProcess in ProcessInstanceImpl throws a NullPointerException
              joploya Newbie

              Anyone to help please?


              I don't succed to debug this.


              This is the code of knowledgeSession producer :


              log.debug("produce the KnowledgeSession ...");
                                  KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
                List<Resource> resources = getProcessDefinitionList();
                                  for (Resource resource : resources) {
                                            kbuilder.add(resource, ResourceType.BPMN2);
                                  if ( kbuilder.hasErrors() ) {
                                       log.error( kbuilder.getErrors().toString() );
                                  KnowledgeBase kbase = kbuilder.newKnowledgeBase();
                                  Environment env = KnowledgeBaseFactory.newEnvironment();
                                  env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );
                                  if(kbase != null){
                                            System.out.println("knowledge base NOT null");
                                            for(org.drools.definition.process.Process p :kbase.getProcesses()){
                                                      System.out.println(" - process "+p.getName()+" ["+p.getId()+"]");
                                  StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
                                  System.out.println(" !!!! DEBUG SESSION PERSISTENCE : new session with id : "+ksession.getId()+" !!!!");

              And the associated log :


              knowledge base NOT null
               - process newcpbeforem29commontrunk [com.st.ams.flows.newcpbeforem29commontrunk]
               - process newcpbeforem29 [com.st.ams.flows.newcpbeforem29]
               - process newfinishedgood [com.st.ams.flows.newfinishedgood]
               - process DataCorrections [com.st.ams.flows.datacorrections]
               - process newproductline [com.st.ams.flows.newproductline]
                      (lastModificationDate, rulesByteArray, startDate, OPTLOCK)
                      (?, ?, ?, ?)
               !!!! DEBUG SESSION PERSISTENCE : new session with id : 32 !!!!

              After that I try to retrieve all tasks and display task information. This use the method below :


              public Object getProcessVariable(Long processInstanceId, Long taskId, String key){
                                  Object retObj = null;
                                  WorkflowProcessInstance wpi = (WorkflowProcessInstance)kSession.getProcessInstance(processInstanceId);
                                  if((wpi == null) || (wpi.getVariable(key) == null)){
                                            System.out.println("workflow process instance is null :-(");
                                            System.out.println("workflow process instance is NOT null :-)");
                                            retObj = wpi.getVariable(key);
                                            //node info
                                            System.out.println("is knowledge runtime null? "+(kSession.getSessionClock() == null));
                                            System.out.println("list of node instance : ");
                                            for(NodeInstance iNode : wpi.getNodeInstances()){
                                                      Node node = iNode.getNode();
                                  return retObj;

              and the associated log :


              workflow process instance is NOT null :-)
              is knowledge runtime null? false
              list of node instance :

              but then I have the same error as for my first post in the ProcessInstanceImpl class


              Caused by: java.lang.NullPointerException
                        at org.jbpm.process.instance.impl.ProcessInstanceImpl.getProcess(ProcessInstanceImpl.java:68) [jbpm-flow-5.4.0.Final.jar:5.4.0.Final]
                        at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.getWorkflowProcess(WorkflowProcessInstanceImpl.java:181) [jbpm-flow-5.4.0.Final.jar:5.4.0.Final]
                        at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.getNodeContainer(WorkflowProcessInstanceImpl.java:69) [jbpm-flow-5.4.0.Final.jar:5.4.0.Final]
                        at org.jbpm.workflow.instance.impl.NodeInstanceImpl.getNode(NodeInstanceImpl.java:103) [jbpm-flow-5.4.0.Final.jar:5.4.0.Final]
                        at com.st.ams.task.management.TaskManager.getProcessVariable(TaskManager.java:234) [classes:]

              It may be the kruntime that is null but how it is null?

              • 4. Re: getProcess in ProcessInstanceImpl throws a NullPointerException
                Marco Rietveld Novice

                What's probably happening is that the code you're calling is happening outside of a transaction.


                You've posted the code above, so you can see that the NPE is probably happening because the ProcessInstanceImpl.kruntime field is null.


                The kruntime field in the ProcessInstanceImpl is set to null as soon as the transaction is closed. This has to do with making sure that jBPM doesn't cache old copies of processinstances.


                So, in this case, when you call


                the transaction has already ended (it ended within the ksession.getProcessInstance() method).


                May I ask why you want a list of NodeInstances? There may be other ways to get the information that you're looking for. Also, at the moment that you're looking for the node instances, there shouldn't be any or otherwise you're betting on a race condition.


                1 of 1 people found this helpful
                • 5. Re: getProcess in ProcessInstanceImpl throws a NullPointerException
                  joploya Newbie

                  Thank you for your answer Marco. You are totally right ; I made a step by step debugging and I could see a call to jpm.dispose() so this may be linked to the closed transaction.


                  But even if I debug several time I don't really understand what happens and why. What can I do to avoid the transaction to close?


                  Bellow there are some screenshot of the debug :



                  then getProcess() is called 7 times :


                  And when it goes to the next step


                  all become null!


                  • 6. Re: getProcess in ProcessInstanceImpl throws a NullPointerException
                    Marco Rietveld Novice

                    There are one or two things you can do to keep the tx from closing -- but you don't want to go down that road. I've been there, and it just gets complexer and ends up in code that's harder to maintain.


                    (If you are really, really, really sure that you still want to do it after reading this, let me know and I can explain it.)


                    The main reason you don't want to fool around with tx's when working with jBPM is that jBPM is designed to have full control over transactions -- or in other words, when some of the drools/jbpm developers initially designed the persistence mechanism, they designed it only thinking about the use case where drools/jbpm had control over the tx's: later, some changes were made to make it possible for the users to do that, but the design of the core persistence mechanism (the SingleSessionCommandService) doesn't really play nice with that. With Drools/jBPM 6, we've expanded some of the possibilities, and hopefully we'll add even more in the coming year, but, in my very humble opinion, I don't think we're at a point yet where we can encourage users to take tx control away from the engine.


                    In short, once you take control of the tx with jBPM, you're getting into "hacking" territory and you'll be more and more on your own, so to speak.


                    So, having said that, I'm getting back to my original question: why do you want the node instance information? One of the anti-patterns that's emerged with BPM is "reaching into the engine": you're always better of treating the engine as a black box because it makes it easier to migrate to new versions of the engine (or other engines) in the long run. It's the same principle as webservices -- or even just information encapsulation.

                    • 7. Re: getProcess in ProcessInstanceImpl throws a NullPointerException
                      Marco Rietveld Novice

                      Having written what I've written above (about not fooling around with tx's and the engine), if you are really, really, really, really, really, really sure that you want to go down that road, you can do the following:


                      Start and  end the JTA transaction yourself.


                      It's that simple: the core persistence mechanism in Drools/jBPM checks to see if there's an active transaction first before starting one -- and it also keeps track of whether or not it started a transaction. That way, it will  not commit the transaction if it has also not started the transaction.


                      However, as Elmer Fudd used to say, be vewy, vewy careful when you're doing this. Open the tx, do your thing with the engine and close the tx immediately: remember that the process instance state is saved only when the transaction commits. If you do 2 or more actions that modify the process instance, you'll probably be okay. If you modify the processs instance state and "reach into the engine" to do weird things, good luck!


                      Some of the other core committers to the jBPM project would disagree with me about this: they might say "Ahh, Marco's being a wimp -- there are no problems with tx's. Go ahead and have a transaction party!". They will be right 99% of the time -- but if you get into complicated (high load/performance) situations with jBPM and user-controlled tx's, I'd wouldn't bet on it.

                      • 8. Re: getProcess in ProcessInstanceImpl throws a NullPointerException
                        joploya Newbie

                        OK I understand your explainations about jbpm black box.


                        About the nodeInstance it is to look for node metada as I am interesting about Shobhit Tyaqi question : https://community.jboss.org/message/806501#806501


                        But this is effectively not critical for my project. However, I encounter the same problem for a pillar method of my project that consists in setting process variable at each step of all my processes :


                        public void setProcessVariable(Long processInstanceId, String key, Object object){
                                            WorkflowProcessInstance wpi = (WorkflowProcessInstance)kSession.getProcessInstance(processInstanceId);
                                            if((wpi == null) || (wpi.getVariable(key) == null)){
                                                      System.out.println("workflow process instance is null :-(");
                                                      System.out.println("workflow process instance is NOT null :-)");
                                                      wpi.setVariable(key, object);

                        So this is why I need your help.


                        Many thank for all your answers.


                        • 9. Re: getProcess in ProcessInstanceImpl throws a NullPointerException
                          Marco Rietveld Novice

                          Interesting.. well, if you can keep a secret ;D, the metadata that Shobhit was asking about is actually available. The jBPM parser parses and stores that information and it's available at (process instance) runtime. Actually, I'm pretty sure it's even available directly from the knowledge base. Of course, the minute we start trying hat metadata, the BPM engine is no longer a black box... I'll make a quick code example and post it on this thread in the next couple days.



                          But back to your process variable question: unfortunately, the only way to set process variables in a process is at the very beginning, with the following method:


                          {code}ksession.startProcess(String processId, Map<String, Object> parameters){code}


                          The String key in the parameters Map should match the name of the.. (searching brain for bpmn2 knowledge... ) property element in the process element. The property's itemSubjectDef should reference a itemDefintiion element defined with the correct data type ("java.lang.String", for example) above/outside the process element in your BPMN2.


                          At the moment, definining or adding a process variable (that you want to access outside of the engine) is only possible at process instance creation -- with the method described above. At least, as far as I know..  I'll check with some of the other dev's to make sure.

                          • 10. Re: getProcess in ProcessInstanceImpl throws a NullPointerException
                            Marco Rietveld Novice

                            Argh -- Sandra, how do you make the java code look pretty (with colors, etc.. )? It didn't work for me. :/

                            • 11. Re: getProcess in ProcessInstanceImpl throws a NullPointerException
                              joploya Newbie

                              Lol, I'm looking forward to see your example about accessing metadatas!


                              To make the java code looks like java code, you must use the advanced editor :

                              click on add response
                              then click on advanced editor at right up corner outside the editing panel and accept to exit the page (normally your text is not remove).
                              finally select the code click on >> button and highlighting.

                              Easy compare to implement Jbpm!


                              If I can abuse a little more of your patience, I will explain you why I have to set process variable :

                              I use them to set the userId and groupId at each step for the next step. So I already use the parameter map when I start process :


                              Map<String, Object> variables = new HashMap<String, Object>();
                                                  variables.put("flowId", entity.getFlowId());
                                                  variables.put("flowType", entity.getFlowType().getFlowAcronym());
                                                  variables.put("codifType", codifType);
                                                  variables.put("groupAssign", codifType+"_P_ENG");
                                                  variables.put("userAssign", userAssign);
                                                  variables.put("line", line);
                                                  taskManager.startProcess("com.st.ams.flows.newfinishedgood", variables);
                                         * Start a new processInstance of an existing Process
                                         * and set the variables of this instance
                                         * @param processId, map of variables
                                         * @return ProcessInstance created
                                        public ProcessInstance startProcess(String processId, Map<String, Object> parameters){
                                                  ProcessInstance p = kSession.startProcess(processId,parameters);
                                                  return p;


                              But one of my main targets using jbpm is to manage dynamic assignement, and I was starting doing this with the methode setVariables :


                              private void manageInstanceFgPlanStep2() {
                                                  log.debug("Normally this method is called after sending email : " + "it validate the step 2");
                                                  String userAssign = newFinishedGoodBean.getFlowEntity().getpEngPartEntity().getRecipientPoBeName();
                                                  log.debug(" ->userAssign = "+userAssign); 
                                                  taskManager.setProcessVariable(taskManager.getManageTask().getProcessInstanceId(), "userAssign", userAssign);
                                                  taskManager.setProcessVariable(taskManager.getManageTask().getProcessInstanceId(), "groupAssign", 


                              This method to set variables worked very good until last week, I have test several flows from start to end... The major change I made is to persist session in database in order to retrive user task even if the application server crashes. So just one line :


                              StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

                              replace by

                              StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);


                              Are you a Jbpm developer? That must be awesome to take part to this project.

                              • 12. Re: getProcess in ProcessInstanceImpl throws a NullPointerException
                                Marco Rietveld Novice

                                I am lucky enough to spend most of my time working on jBPM -- and it is indeed awesome!


                                One approach to your problem is to switch from "pass-by-value" to "pass-by-reference" for your variable assignment. In other words, instead of passing the primitive values (String, int, etc.), you can pass an object containing these values as a parameter. If you want to retrieve the values later, you simply make sure that your code keeps a reference to the object so that you can retrieve and modify the (possibly changed) values.


                                This means the following:

                                1. Making sure that the object used is in the classpath -- you need to put in the classpath of the application server or your war.
                                2. Correctly referencing and extracting the information from your object -- whether that's in your WorkItemHandler implementation or a scriptTask.


                                Because of persistence, the object also needs to be serialized. Hmm.. I'll make a example of this today/tomorrow and post a link for you here.

                                • 13. Re: getProcess in ProcessInstanceImpl throws a NullPointerException
                                  joploya Newbie

                                  Hello Marco,


                                  I'm not sur to understand how to put an object in the classpath of the war.


                                  I think I will try to modify my processes and add output parameters. And then map output parameters with variables parameters inside the process and if it works I will post it.

                                  • 14. Re: getProcess in ProcessInstanceImpl throws a NullPointerException
                                    Marco Rietveld Novice

                                    Hi Sandra,


                                    With regards to an object in the classpath of your war, I mean the following:


                                    1. Include the class in the war.
                                    2. Add a jar with the class to the library of your server.
                                      1. For JBoss AS 7 (standalone), that would be in the standalone/lib directory.
                                      2. For JBoss AS 5/EAP 5 (default profile), that would be in the server/default/lib directory.


                                    Also, I'm (slowly) making an example for you here: https://github.com/mrietveld/jbpm-more-examples.


                                    If you have an example of a BPMN2 file that you could pass to me (with which you would like to use dynamic assignment/process variables), that would be great!

                                    1 2 Previous Next