cancel
Showing results for 
Search instead for 
Did you mean: 

NullPointerException if throw a not catched exception/error

nandoztx
Champ in-the-making
Champ in-the-making
Hi guys!
Maybe this behavior must be a bug… a don't know.
If, inside a scriptTask or serviceTask, whatever, throw a unexpected BpmnError like: "Hulk smash":
and haven't a generic boundaryEvent to detect it or a specific errorEventDefinition to treat this, so, a NullPointerException is throwed! But why?

throw new BpmnError("Hulk smash");
I take a look in this code at AbstractEventAtomicOperation:

public void execute(InterpretableExecution execution) {
    ScopeImpl scope = getScope(execution);
List<ExecutionListener> exectionListeners = scope.getExecutionListeners(getEventName());
    int executionListenerIndex = execution.getExecutionListenerIndex();
(…)
the problem is this var scope, this is null when haven't a boundaryEvent to catch exceptions…
The most weard is the warning before error:

11/10/2012 10:27:33 org.activiti.engine.impl.bpmn.helper.ErrorPropagation propagateError
INFO: testeScript throws error event with errorCode 'Hulk smash', but no catching boundary event was defined. Execution will simply be ended (none end event semantics).
11/10/2012 10:29:51 org.activiti.engine.impl.interceptor.CommandContext close
GRAVE: Error while closing command context
java.lang.NullPointerException
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:42)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:80)
(…)
If "Execution will simply be ended (none end event semantics)." , why NullPointerException?

I can avoid this exception if put a generic or specific exception treatment, my code:


<scriptTask id="testeScript" name="Teste script" scriptFormat="groovy">
  <script><![CDATA[
   osama = "Osama";
        throw new BpmnError("Hulk smash");                     
   osama2="Osama2222";      
  ]]></script>
</scriptTask>

<boundaryEvent id="catchErrorGeneric" attachedToRef="testeScript" cancelActivity="true">
   <errorEventDefinition id="genericError" />
</boundaryEvent>

<sequenceFlow sourceRef="catchErrorGeneric" targetRef="printaGeneric" />

<scriptTask id="printaGeneric" name="Generic script" scriptFormat="groovy">
  <script><![CDATA[
        println("generic error/exception man!");
  ]]></script>
</scriptTask>

<sequenceFlow sourceRef="printaGeneric" targetRef="theEnd" />

Thank's in advance.
7 REPLIES 7

frederikherema1
Star Contributor
Star Contributor
Can you poor this into an executable unit-test, so we can see the exact process and reproduce this issue? See the sticky in the forum on how to do this.

Judging from the process extract , I don't see anything who wrong that should cause the NPE. The execution should indeed just simply be ended.
Also, be careful with mentioning "osama" in your posts, don't want the FBI to flag activiti as a terrorist engine Smiley Wink

nandoztx
Champ in-the-making
Champ in-the-making
Can you poor this into an executable unit-test, so we can see the exact process and reproduce this issue? See the sticky in the forum on how to do this.

Judging from the process extract , I don't see anything who wrong that should cause the NPE. The execution should indeed just simply be ended.
Also, be careful with mentioning "osama" in your posts, don't want the FBI to flag activiti as a terrorist engine Smiley Wink
Hi, I can do this test, this posted code protect this NPE:
<boundaryEvent id="catchErrorGeneric" attachedToRef="testeScript" cancelActivity="true">
   <errorEventDefinition id="genericError" />
</boundaryEvent>
but without this boundaryEvent throw a NPE, because, haven't a catch boundaryEvent.

Thank's for you reply.

nandoztx
Champ in-the-making
Champ in-the-making
Also, be careful with mentioning "osama" in your posts, don't want the FBI to flag activiti as a terrorist engine Smiley Wink
Thank's, I will take careful Smiley Happy, terrorist engine omg! euhuaeh

nandoztx
Champ in-the-making
Champ in-the-making
Hi,
this is my simple test to show the NPE (NullPointerException) when haven't a catch exception (by activiti tags) in activiti xml model.
Details in README file.

Problem at 'com org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation', line 34, if 'scope' is 'null' throw NPE.
It occurrs when have a 'BpmnError' and haven't a BoundaryEvent to catch this specific exeption.
If have a generic exception interceptor like this:


<boundaryEvent id="catchErrorGeneric" attachedToRef="testScript" cancelActivity="true">
<errorEventDefinition id="genericError" />
</boundaryEvent>

so, the exception will be catched by this 'catchErrorGeneric'.

My question: Why NPE ? it's a bug or is my bad usage?

Have I trouble in activiti forum? I can't upload any file, and the message is showed in red: "Could not upload attachment to ./files/3023_c5cf82184f989fdb22992c472e2f1da3."

Because this I will put the code here:

use this code base:
https://github.com/Activiti/activiti-unit-test-template
create a new project from eclipse, update dependencies with maven2
add this dependencie in the pom.xml:

<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.0.1</version>
</dependency>

update this line
@Deployment(resources = {"org/activiti/test/my-process.bpmn20.xml"}) by this: @Deployment(resources = {"org/activiti/test/catchingException.bpmn20.xml"}) in org.activiti.MyUnitTest.java

make a file with name: "catchingException.bpmn20.xml" in: "activiti-unit-test-bug-nullpointer\src\test\resources\org\activiti\test"
put this code inside:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlnsSmiley Surprisedmgdc="http://www.omg.org/spec/DD/20100524/DC"
xmlnsSmiley Surprisedmgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="error NullPointerException (bug ?) - nandoztx">

<error id="errorOne" name="testExceptionOne" errorCode="exceptionOne" />
<error id="errorTwo" name="testExceptionTwo" errorCode="exceptionTwo" />

<process id="catchingException" name="catch any exception - nandoztx">

  <startEvent id="start" name="Start" />

  <sequenceFlow sourceRef="start" targetRef="firstScript" />
 
  <!– test if this 'var1' var is serialized, but is not –>
  <scriptTask id="firstScript" name="Teste script"
   scriptFormat="groovy">
   <script><![CDATA[
   var1 = "VAR1!";
   ]]></script>
  </scriptTask>
 
  <sequenceFlow sourceRef="firstScript" targetRef="testScript" />

  <scriptTask id="testScript" name="Teste script"
   scriptFormat="groovy">
   <script><![CDATA[
   //activiti loves BpmnError Smiley Wink
   import org.activiti.engine.delegate.BpmnError;

   var2 = "VAR2";
  
   throw new BpmnError("bananaException"); // will throw NPE (if not have a generic catch exception, like this "catchErrorGeneric")
   //throw new BpmnError("exceptionTwo"); //will be catched
  
   var3="VAR3";
     
   ]]></script>
  </scriptTask>

  <sequenceFlow sourceRef="testScript" targetRef="theEnd" />

  <!– flag cancelActivity is used to signal to process terminate when have task not finished yet (with erros) –>
  <boundaryEvent id="catchErrorOne" attachedToRef="testScript" cancelActivity="true">
   <errorEventDefinition id="one" errorRef="errorOne" />
  </boundaryEvent>
  <boundaryEvent id="catchErrorTwo" attachedToRef="testScript" cancelActivity="true">
   <errorEventDefinition id="two" errorRef="errorTwo" />
  </boundaryEvent>
 
  <!– if enable this generic catch BpmnError, no have NPE and will print "generic error/exception man!" –>
  <!– <boundaryEvent id="catchErrorGeneric" attachedToRef="testScript" cancelActivity="true">
   <errorEventDefinition id="genericError" />
  </boundaryEvent> –>

  <!– if event has not directed, so process will be 'flying' in the DB without user to get him ? –>
  <sequenceFlow sourceRef="catchErrorOne" targetRef="printOne" />
  <sequenceFlow sourceRef="catchErrorTwo" targetRef="printTwo" />
  <!– uncomment this code below if you has uncomment that "catchErrorGeneric", this is a sequence flow –>
  <!– <sequenceFlow sourceRef="catchErrorGeneric" targetRef="printGeneric" /> –>

  <scriptTask id="printGeneric" name="Generic script" scriptFormat="groovy">
   <script><![CDATA[ println("generic error/exception man!");
   ]]></script>
  </scriptTask>

  <scriptTask id="printOne" name="Script error one" scriptFormat="groovy">
   <script><![CDATA[ println("ERROR ONE CATCHED!!!");
   ]]></script>
  </scriptTask>

  <scriptTask id="printTwo" name="Script error two" scriptFormat="groovy">
   <script><![CDATA[ println("ERROR TWO CATCHED!!!");
   ]]></script>
  </scriptTask>

  <sequenceFlow sourceRef="printOne" targetRef="theEnd" />
  <sequenceFlow sourceRef="printTwo" targetRef="theEnd" />
  <sequenceFlow sourceRef="printGeneric" targetRef="theEnd" />

  <endEvent id="theEnd"/>    

</process>

</definitions>

After:
maven clean;
clean project;

right click on main class: org.activiti.MyUnitTest.java and run it with JUnit test.
It's done, when activiti solve this problem with upload in forum, I will post the complete project.

jbarrez
Star Contributor
Star Contributor

nandoztx
Champ in-the-making
Champ in-the-making
Thank's.
I'm praying for fix this Smiley Wink

nandoztx
Champ in-the-making
Champ in-the-making