2 Replies Latest reply on Feb 9, 2007 4:10 AM by Sébastien MIGNIOT

    NullPointerException executing timer

    Dani Kenan Newbie

      We have a rather simple mechanism to execute timers.
      Following is the relevant code:

       private static final String EQL_FIND_TIMER_BY_ID = "select ti "
       + "from org.jbpm.scheduler.exe.Timer as ti "
       + "where ti.id = :timerId";
      
       @SuppressWarnings("unchecked")
       public void executeTimer(final long timerId) {
       JbpmSession jbpmSession = getJbpmSessionFactory().openJbpmSessionAndBeginTransaction();
       Session hibernateSession = jbpmSession.getSession();
       SchedulerSession schedulerSession = jbpmSession.getSchedulerSession();
       try {
       Query query = hibernateSession.createQuery(EQL_FIND_TIMER_BY_ID);
       Timer timer = (Timer) query.setLong("timerId", timerId).uniqueResult();
      
       if (timer.isDue()) {
       timer.execute();
       }
      
       } catch (Exception e) {
       LOG.error("Error executin timer id " + timerId, e);
       } finally {
       jbpmSession.close();
       }
       }
      


      any call to executeTimer with an id of a due timer would generate the following error:



      java.lang.NullPointerException
       at org.jbpm.graph.def.GraphElement.getRuntimeActionsForEvent(GraphElement.java:208)
       at org.jbpm.graph.def.GraphElement.fireAndPropagateEvent(GraphElement.java:153)
       at org.jbpm.scheduler.exe.Timer.execute(Timer.java:54)
       at com.cbittech.peglogic.core.engine.JbpmWrapperBean.executeTimer(JbpmWrapperBean.java:256)
       at com.cbittech.peglogic.core.engine.JbpmWrapperTest.testExecuteTimers(JbpmWrapperTest.java:88)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at junit.framework.TestCase.runTest(TestCase.java:154)
       at junit.framework.TestCase.runBare(TestCase.java:127)
       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:118)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
      



      This is due to the fact that in GraphElement.getRuntimeActionsForEvent the executionContext has a null processInstance.

      What is wrong?



        • 1. Re: NullPointerException executing timer
          Sébastien MIGNIOT Newbie

          We have the same issue using the simplest workflow here :

          <state name="validateIn20seconds">
           <transition name="" to="validated" />
           <transition name="missed" to="notvalidated" />
           <timer duedate="20 seconds" transition="missed">
           <action class="action.DoNothing" />
           </timer>
           </state>
           <state name="validated">
           <transition name="" to="end"></transition>
           </state>
           <state name="notvalidated">
           <transition name="" to="end"></transition>
           </state>
          


          We're using the SchedulerServlet to execute timers
          so the error is not due to your mechanism. We obtain
          the same error :

          INFO: runtime exception while executing timers
          java.lang.NullPointerException
           at org.jbpm.graph.def.GraphElement.getRuntimeActionsForEvent(GraphElement.java:259)
           at org.jbpm.graph.def.GraphElement.fireAndPropagateEvent(GraphElement.java:186)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:147)
           at org.jbpm.graph.node.State$$EnhancerByCGLIB$$d55a4606.fireAndPropagateEvent(<generated>)
           at org.jbpm.scheduler.exe.Timer.execute(Timer.java:77)
           at org.jbpm.scheduler.impl.SchedulerThread.executeTimers(SchedulerThread.java:118)
           at org.jbpm.scheduler.impl.SchedulerThread.run(SchedulerThread.java:70)


          No idea what the solution is ...
          We're using Jbpm as recommended by the docs.


          • 2. Re: NullPointerException executing timer
            Sébastien MIGNIOT Newbie

            Found the solution - for my problem at least - :
            We were not enclosing all transactions by jbpmConfiguration.createJbpmContext() and
            context.close() . We were using a single context
            hold in a singleton and never closed.

            Using a strategy of opening and closing contexts
            properly for all usages of the workflow solved
            the issue.

            Maybe you should check your code for proper
            nesting of context transactions ?