cancel
Showing results for 
Search instead for 
Did you mean: 

NPE in 5.11 when deleting a process from a service task

conradi
Champ in-the-making
Champ in-the-making
After updating activiti from 5.9 -> 5.11 one of our test cases stopped working:

There is a UserTask which ends in a gateway which in turn triggers a ServiceTask, and within that ServiceTask we call activitiRuntimeService.deleteProcessInstance(…).
While this has worked fine in 5.9 it fails with a NullPointerException in 5.11. If I fix the NPE's (there are two of them):

Index: activiti-5.11/modules/activiti-engine/src/main/java/org/activiti/engine/impl/bpmn/behavior/AbstractBpmnActivityBehavior.java
===================================================================
— activiti-5.11/modules/activiti-engine/src/main/java/org/activiti/engine/impl/bpmn/behavior/AbstractBpmnActivityBehavior.java        (Revision 2937)
+++ activiti-5.11/modules/activiti-engine/src/main/java/org/activiti/engine/impl/bpmn/behavior/AbstractBpmnActivityBehavior.java        (Arbeitskopie)
@@ -51,7 +51,11 @@
   }
  
   protected boolean hasCompensationHandler(ActivityExecution execution) {
-    return execution.getActivity().getProperty(BpmnParse.PROPERTYNAME_COMPENSATION_HANDLER_ID) != null;
+    if (execution.getActivity() == null) {
+      return false;
+    } else {
+      return execution.getActivity().getProperty(BpmnParse.PROPERTYNAME_COMPENSATION_HANDLER_ID) != null;
+    }
   }

   protected void createCompensateEventSubscription(ActivityExecution execution) {
Index: activiti-5.11/modules/activiti-engine/src/main/java/org/activiti/engine/impl/bpmn/behavior/BpmnActivityBehavior.java
===================================================================
— activiti-5.11/modules/activiti-engine/src/main/java/org/activiti/engine/impl/bpmn/behavior/BpmnActivityBehavior.java        (Revision 2937)
+++ activiti-5.11/modules/activiti-engine/src/main/java/org/activiti/engine/impl/bpmn/behavior/BpmnActivityBehavior.java        (Arbeitskopie)
@@ -84,6 +84,9 @@
       log.fine("Leaving activity '" + execution.getActivity().getId() + "'");
     }

+    if (execution.getActivity() == null) {
+        return;
+    }
     String defaultSequenceFlow = (String) execution.getActivity().getProperty("default");
     List<PvmTransition> transitionsToTake = new ArrayList<PvmTransition>();

the use case works again.
But I fear that I have opened another can of worms.

What is the suggested approach in such a case (I have tried to use activiti:async="true", but to no avail)?

TIA, Heinz-Dieter
8 REPLIES 8

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
which processinstance do you try to delete? The one you are currently in?

conradi
Champ in-the-making
Champ in-the-making
which processinstance do you try to delete? The one you are currently in?

yes.
In the gateway, the decision is made that everything is done and that this process should be deleted for this user.

trademak
Star Contributor
Star Contributor
Hi,

The change in the AbstractBpmnActivityBehavior is valid I think but the BpmnActivityBehavior had the same code in 5.9, so why is that needed now?
Is it not a better solution to use the Terminate end event for your use case?

Best regards,

conradi
Champ in-the-making
Champ in-the-making
Hi,

The change in the AbstractBpmnActivityBehavior is valid I think but the BpmnActivityBehavior had the same code in 5.9, so why is that needed now?

I have notice the same thing, and I have no idea what change between 5.9 and 5.11 is responsible here.
This is why I am a bit anxious about the patch which just checks for the NPE.

Should I open a jira bug?

Is it not a better solution to use the Terminate end event for your use case?

Unfortunately, it is not only the current workflow which is terminated, but every workflow of a special group.
One could perhaps terminate everything but the current process in the service task and then use the terminate end event
(btw, the terminate end event is not mentioned in the user guide, but there are examples in the source).

Thanks

vivverma
Champ in-the-making
Champ in-the-making
Did we get any solution for the above issue? I am facing the same issue were i need to end the process Instance execution on occurrence of an error . Do we have any alternatives apart from runtimeService.deleteProcessInstance(pid) ??
P.S. Wrapping the Workflow in a callActiviti or Sub process and adding an ErrorBoundary event is not an option in my case.

vivverma
Champ in-the-making
Champ in-the-making
Any updates on the above topic?

jbarrez
Star Contributor
Star Contributor
Like Tijs said, the best approach is a terminate end event.
Of course, if it's about multiple processes, then deleteProcessInstance() is the only option you have

mmaker1234
Champ in-the-making
Champ in-the-making
<b>@vivverma</b> How do you register this error? The ErrorBoundary event is just a "shortcut" for checking error conditions on each step of the process. If the wrapping is not suitable to you you can still use the "old school" and branch each step with a transition to the process end in case of an error.

<b>@Joram</b> Please note that a call of <code>deleteProcessInstance()</code> from within the process execution, including the delegates, leads to NPE while writing to the history tables. At least this is what we observe with history="full".