Uploaded image for project: 'jBPM'
  1. jBPM
  2. JBPM-2840

NullPointerException when ExecutionImpl.createVariable() with isHistoryEnabled=true

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • jBPM 4.4
    • jBPM 4.3
    • None
    • None

      When I want to create a history enabled variable, the ProcessInstanceImpl will invoke variable.seValue(), in this method, variable will fire a VariableUpdate command. This command will try to get the HistoryVariableImpl and update it. But at this moment, the HistoryVariableImpl has not been created, so there will be a NullPointerException.

      I think we should check whether the HistoryVariableImpl instance exists, then decide to update it or not.

      The used code is like this:
      ProcessInstance processInstance = executionService.startProcessInstanceByKey("Normal");

      EnvironmentImpl environment = ((EnvironmentFactory)processEngine).openEnvironment();
      ((ExecutionImpl)processInstance).createVariable("test", "valuetest","string",true);
      Session session = environment.get(Session.class);
      Transaction tx = session.beginTransaction();
      session.update(processInstance);
      tx.commit();
      environment.close();

      The exception stack trace is like this:

      15:27:28,703 SEV | [BaseJbpmTestCase] TEST THROWS EXCEPTION: null
      java.lang.NullPointerException
      at org.jbpm.pvm.internal.history.events.VariableUpdate.process(VariableUpdate.java:48)
      at org.jbpm.pvm.internal.history.HistorySessionImpl.process(HistorySessionImpl.java:31)
      at org.jbpm.pvm.internal.history.HistoryEvent.fire(HistoryEvent.java:62)
      at org.jbpm.pvm.internal.history.HistoryEvent.fire(HistoryEvent.java:52)
      at org.jbpm.pvm.internal.type.Variable.setValue(Variable.java:97)
      at org.jbpm.pvm.internal.model.ScopeInstanceImpl.createVariableObject(ScopeInstanceImpl.java:140)
      at org.jbpm.pvm.internal.model.ScopeInstanceImpl.createVariable(ScopeInstanceImpl.java:90)
      at com.asset.jupiter.jbpm.processes.Normal.NormalTest.testCreateProcessInstance(NormalTest.java:33)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at junit.framework.TestCase.runTest(TestCase.java:164)
      at org.jbpm.test.BaseJbpmTestCase.runTest(BaseJbpmTestCase.java:80)
      at junit.framework.TestCase.runBare(TestCase.java:130)
      at junit.framework.TestResult$1.protect(TestResult.java:106)
      at junit.framework.TestResult.runProtected(TestResult.java:124)
      at junit.framework.TestResult.run(TestResult.java:109)
      at junit.framework.TestCase.run(TestCase.java:120)
      at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

              swiderski.maciej Maciej Swiderski (Inactive)
              rebody HuiSheng Xu (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: