5 Replies Latest reply on Jan 21, 2014 10:47 AM by Florian Stendel

    JBPM 5.4: NullPointerException in WorkflowProcessInstanceImpl

    Florian Stendel Newbie

      Hi there,


      we currently facing issues were we try to get ProcessInstances from StatefulKnowledgeSession by method-calls to:


      (WorkflowProcessInstance) statefulKnowledgeSession.getProcessInstance(processInstanceId);


      For a couple of ProcessInstances we the following stacktrace:


      17:27:02,015 ERROR [org.drools.persistence.SingleSessionCommandService] (http--127.0.0.1-8080-6) Could not commit session: java.lang.NullPointerException
              at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.setState(WorkflowProcessInstanceImpl.java:252) [jbpm-flow-5.4.0.Final.jar:5.4.0.Final]
              at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.setState(WorkflowProcessInstanceImpl.java:269) [jbpm-flow-5.4.0.Final.jar:5.4.0.Final]
              at org.jbpm.marshalling.impl.AbstractProtobufProcessInstanceMarshaller.readProcessInstance(AbstractProtobufProcessInstanceMarshaller.java:377) [jbpm-flow-5.4.0.Final.jar:5.4.0.Final]
              at org.jbpm.persistence.processinstance.ProcessInstanceInfo.getProcessInstance(ProcessInstanceInfo.java:142) [jbpm-persistence-jpa-5.4.0.Final.jar:5.4.0.Final]
              at org.jbpm.persistence.processinstance.JPAProcessInstanceManager.getProcessInstance(JPAProcessInstanceManager.java:91) [jbpm-persistence-jpa-5.4.0.Final.jar:5.4.0.Final]
              at org.jbpm.process.instance.ProcessRuntimeImpl.getProcessInstance(ProcessRuntimeImpl.java:206) [jbpm-flow-5.4.0.Final.jar:5.4.0.Final]
              at org.drools.common.AbstractWorkingMemory.getProcessInstance(AbstractWorkingMemory.java:1116) [drools-core-5.5.0.Final.jar:5.5.0.Final]
              at org.drools.impl.StatefulKnowledgeSessionImpl.getProcessInstance(StatefulKnowledgeSessionImpl.java:297) [drools-core-5.5.0.Final.jar:5.5.0.Final]
              at org.drools.command.runtime.process.GetProcessInstanceCommand.execute(GetProcessInstanceCommand.java:48) [drools-core-5.5.0.Final.jar:5.5.0.Final]
              at org.drools.command.runtime.process.GetProcessInstanceCommand.execute(GetProcessInstanceCommand.java:25) [drools-core-5.5.0.Final.jar:5.5.0.Final]
              at org.drools.command.impl.DefaultCommandService.execute(DefaultCommandService.java:36) [drools-core-5.5.0.Final.jar:5.5.0.Final]
              at org.drools.persistence.SingleSessionCommandService.execute(SingleSessionCommandService.java:373) [drools-persistence-jpa-5.5.0.Final.jar:5.5.0.Final]
              at org.drools.command.impl.CommandBasedStatefulKnowledgeSession.getProcessInstance(CommandBasedStatefulKnowledgeSession.java:125) [drools-core-5.5.0.Final.jar:5.5.0.Final]
              at sun.reflect.GeneratedMethodAccessor113.invoke(Unknown Source) [:1.7.0_45]
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_45]
              at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_45]
              at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
              at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
              at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
              at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
              at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
              at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
              at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) [spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
              at com.sun.proxy.$Proxy189.getProcessInstance(Unknown Source)

      This points to a codeblock which is executed when the processintance is in state ABORTED or state COMPLETED.

       

      1. Does it mean the persisted processInstance is allready completed/aborted? (...AbstractProtobufProcessInstanceMarshaller is part of the call hierarchy)

       

      2. We try to get the according processinstances while processing an active human task. Do we have an inconsistent state here ? (An aborted/completed pInstance can't have active human tasks, can it?)

        • 1. Re: JBPM 5.4: NullPointerException in WorkflowProcessInstanceImpl
          Maciej Swiderski Master

          can you provide more details about when and how you get the process instance. The NPE is thrown because there is no kruntime associated with process instance which usually means that the process instance has benn already disconnected from the engine which always happen on transaction completion. So question is how do you manage transactions and if there is any other work that might cause the process instance to be disconnected.

           

          HTH

          • 2. Re: JBPM 5.4: NullPointerException in WorkflowProcessInstanceImpl
            Florian Stendel Newbie

            Hmm.

             

             

            We have a view listing all active human tasks.

            For each of those listed tasks some additional data is displayed, which has been determined by database queries.

            For about a week now, we display some processvariables as well. (at least we try to)

            Those we query by

             

                 WorkflowProcessInstance workflowProcessInstance = (WorkflowProcessInstance) statefulKnowledgeSession.getProcessInstance(processInstanceId);

             

            and

             

                    workflowProcessInstance.getVariable("VARIABLE_X");

             

             

            Hence, the algorithm/procedure looks like this:

             

            1. Transaction begin

            2. Get all human tasks for User

            3. For each task: query data from database

            4. For each task:

            4a. Get WorkflowProcessInstance (exception occurs for some of them)

            4b. get variable from WorkflowprocessInstance

            5. Display human tasks and according data

            6. Transaction close

             

            The stacktrace occurs just for a couple of specific(allways the same) tasks (3 of ~ 30).

             

            We are using persistence.

             

             

            Thank you for your fast reply

             

             

             

            Btw:

             

            I'm kinda confused by the source of

             

            AbstractProtobufProcessInstanceMarshaller.readProcessInstance(MarshallerReaderContext context):

             

            377        processInstance.setState( _instance.getState() );

            378        long nodeInstanceCounter = _instance.getNodeInstanceCounter();

            379        processInstance.setKnowledgeRuntime( wm.getKnowledgeRuntime() );

             

             

            You first try to setState (which uses kruntime) and set the KnowledgeRuntime afterwards ?

            • 3. Re: JBPM 5.4: NullPointerException in WorkflowProcessInstanceImpl
              Maciej Swiderski Master

              I would recommend to not do 4a and 4b but instead ensure that variables that you need are already part of the task. Fetching process instance on task query time is not really efficient way as the query might be rather bit.

               

              HTH

              • 4. Re: JBPM 5.4: NullPointerException in WorkflowProcessInstanceImpl
                Maciej Swiderski Master

                Florian Stendel wrote:

                Btw:

                 

                I'm kinda confused by the source of

                 

                AbstractProtobufProcessInstanceMarshaller.readProcessInstance(MarshallerReaderContext context):

                 

                377        processInstance.setState( _instance.getState() );

                378        long nodeInstanceCounter = _instance.getNodeInstanceCounter();

                379        processInstance.setKnowledgeRuntime( wm.getKnowledgeRuntime() );

                 

                 

                You first try to setState (which uses kruntime) and set the KnowledgeRuntime afterwards ?

                this is valid code as process instance should never be in state completed or aborted while read from data base. So if that's the case the instance is most likely corrupted.

                 

                HTH

                1 of 1 people found this helpful
                • 5. Re: JBPM 5.4: NullPointerException in WorkflowProcessInstanceImpl
                  Florian Stendel Newbie

                  Thank you very much!

                   

                  I already talked to krisv about the right approach via IRC and recommended it to my team.