7 Replies Latest reply on Mar 20, 2013 9:36 PM by rachirib

    Null Pointer Exception when Rule is used to change process variable value

    thomas.setiabudi

      Hi,

       

      This process and rules works well in JBPM5.3 but it causes Null Pointer Exception in JBPM5.4 when the rule tries to update a process variable value.

       

       

      Any idea why?

      (attached the rule, process flow, and server.log)

       

      If the rule does not update process variable, no error occured.

      Also tried this with eclipse, no error occured too.

      And if I start from fresh install of JBPM Installer, this error does not seem to happen

       

       

       

      Regards,

      Thomas Setiabudi

        • 1. Re: Null Pointer Exception when Rule is used to change process variable value
          swiderski.maciej

          that sounds little bit strange especially when you say that it works ok on clean installation. That could mean that you don't retract process instance from working memory (session) when process is completed. In that case it will try to update variable of a process instance that is not up to date (most likely completed) but still remains in the working memory. Please keep in mind that session including all facts in it is persisted and reloaded on every server restart.

           

          Could you please try using the RuleAwareProcessEventListener as it retracts the process instance automatically when process is completed or retract the process instance manually when you don't need it any more. Before doing this remove the session id file stored in jboss_home/standalone/tmp to enforce jbpm to create new session instead of loading one that was previously persisted.

           

          HTH

          • 2. Re: Null Pointer Exception when Rule is used to change process variable value
            thomas.setiabudi

            hi Maciej,

             

            Trying it right now.

             

            by the way in the session template, RuleAwareProcessEventLister should be registered in  eventListeners section right?

             

            I wrote it like this:

            eventListeners = ["new org.jbpm.process.audit.JPAWorkingMemoryDbLogger(ksession)",
                                  "new org.jbpm.integration.console.listeners.TriggerRulesEventListener(ksession)",
                   "new org.jbpm.process.instance.impl.RuleAwareProcessEventLister()"]

             

            Is it correct?

             

            Regards,

            Thomas Setiabudi

             

            • 3. Re: Null Pointer Exception when Rule is used to change process variable value
              thomas.setiabudi

              Hi Maciej,

               

              I deleted all entry to the database, deleted everything in  jboss_home/standalone/tmp/

               

              and put in the RuleAwareProcessEventLister.

               

              Then start the server again.

              Still got the same null pointer exception error.

               

               

               

              Regards,

              Thomas Setiabudi

              • 4. Re: Null Pointer Exception when Rule is used to change process variable value
                thomas.setiabudi

                I decided to leave the rule and try other process without rule,

                 

                the process is located on different Guvnor package and this process does not have any Business Rule Task Node

                 

                Surprisingly I still got error and the Null Pointer Exception comes from the rule that is stored in different package.

                 

                So I can use my jbpm to start process again only after I delete all rules in Guvnor.

                 

                 

                Why even rule that not related to a process still get executed?

                 

                 

                 

                Regards,

                Thomas Setiabudi

                • 5. Re: Null Pointer Exception when Rule is used to change process variable value
                  swiderski.maciej

                  alright played little bit with it and what most likely is going on is that processInstance that is in the working memory is disconnected - since persistence is involved at the end of transaction process instance is disconnected which means clearing its state like ksession or process etc. So the instance of the process instance in the working memory is out dated. I managed to over come this by preloading process instance in the rule to make sure it will set it on active process instance object. please replace your rule consequence with following:

                   

                  WorkflowProcessInstance p = (WorkflowProcessInstance)kcontext.getKnowledgeRuntime().getProcessInstance($processInstance.getId());

                  p.setVariable("name", "PostNewName");

                   

                  this is for the second rule as the first one is executed as part of the transaction so the process instance instance is still active.

                   

                  Another thing I noticed is that the rule is triggered twice so would be good to review process and rule to confirm it work as expected, unfortunately did not have time for that

                   

                  HTH

                  1 of 1 people found this helpful
                  • 6. Re: Null Pointer Exception when Rule is used to change process variable value
                    thomas.setiabudi

                    Hi Maciej,

                     

                    Thank you for the tips, will give that a try and post back the result.

                     

                    Then, how about the rules used in other process, is it true that all rules in the guvnor will be fired regardless of what is the process being executed?

                     

                     

                    Regards,

                    Thomas Setiabudi

                    • 7. Re: Null Pointer Exception when Rule is used to change process variable value
                      rachirib

                      Thomas, Did you Fix it?