AnsweredAssumed Answered

NullPointerException if throw a not catched exception/error

Question asked by nandoztx on Oct 11, 2012
Latest reply on Oct 16, 2012 by nandoztx
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
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(
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">
   osama = "Osama";
        throw new BpmnError("Hulk smash");                     

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

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

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

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

Thank's in advance.