1

I am trying to suspend the process instance for user interaction to do an action like accept or reject the process flow.

public class UserWorkflowTaskListener implements ExecutionListener {
    @Override
    public void notify(DelegateExecution execution) {
        runtimeService.suspendProcessInstanceById(execution.getProcessInstanceId());
    }
}

but its give me an error

2019-09-23 16:48:01.524 ERROR 26851 — [enerContainer-1] o.f.c.e.impl.interceptor.CommandContext : Error while closing command context

java.lang.NullPointerException: null
    at com.rpa.core.process.tasklistener.UserWorkflowTaskListener.notify(UserWorkflowTaskListener.java:75) ~[classes/:na]
    at org.flowable.engine.impl.delegate.invocation.ExecutionListenerInvocation.invoke(ExecutionListenerInvocation.java:35) ~[flowable-engine-6.4.0.jar:6.4.0]
    at org.flowable.engine.impl.delegate.invocation.DelegateInvocation.proceed(DelegateInvocation.java:35) ~[flowable-engine-6.4.0.jar:6.4.0]
    at org.flowable.engine.impl.delegate.invocation.DefaultDelegateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:26) ~[flowable-engine-6.4.0.jar:6.4.0]
    at org.flowable.engine.impl.bpmn.helper.ClassDelegate.notify(ClassDelegate.java:99) ~[flowable-engine-6.4.0.jar:6.4.0]
    at org.flowable.engine.impl.bpmn.listener.ListenerNotificationHelper.executeExecutionListeners(ListenerNotificationHelper.java:79) ~[flowable-engine-6.4.0.jar:6.4.0]
    at org.flowable.engine.impl.agenda.AbstractOperation.executeExecutionListeners(AbstractOperation.java:78) ~[flowable-engine-6.4.0.jar:6.4.0]
    at org.flowable.engine.impl.agenda.AbstractOperation.executeExecutionListeners(AbstractOperation.java:69) ~[flowable-engine-6.4.0.jar:6.4.0]
    at org.flowable.engine.impl.agenda.ContinueProcessOperation.executeSynchronous(ContinueProcessOperation.java:141) ~[flowable-engine-6.4.0.jar:6.4.0]
    at org.flowable.engine.impl.agenda.ContinueProcessOperation.continueThroughFlowNode(ContinueProcessOperation.java:113) ~[flowable-engine-6.4.0.jar:6.4.0]
    at org.flowable.engine.impl.agenda.ContinueProcessOperation.continueThroughSequenceFlow(ContinueProcessOperation.java:311) ~[flowable-engine-6.4.0.jar:6.4.0]
    at org.flowable.engine.impl.agenda.ContinueProcessOperation.run(ContinueProcessOperation.java:79) ~[flowable-engine-6.4.0.jar:6.4.0]
    at org.flowable.engine.impl.interceptor.CommandInvoker.executeOperation(CommandInvoker.java:88) ~[flowable-engine-6.4.0.jar:6.4.0]
    at org.flowable.engine.impl.interceptor.CommandInvoker.executeOperations(CommandInvoker.java:72) ~[flowable-engine-6.4.0.jar:6.4.0]
    at org.flowable.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:56) ~[flowable-engine-6.4.0.jar:6.4.0]
    at org.flowable.engine.impl.interceptor.BpmnOverrideContextInterceptor.execute(BpmnOverrideContextInterceptor.java:25) ~[flowable-engine-6.4.0.jar:6.4.0]
    at org.flowable.common.engine.impl.interceptor.TransactionContextInterceptor.execute(TransactionContextInterceptor.java:53) ~[flowable-engine-common-6.4.0.jar:6.4.0]
    at org.flowable.common.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:71) ~[flowable-engine-common-6.4.0.jar:6.4.0]
    at org.flowable.common.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:49) [flowable-spring-common-6.4.0.jar:6.4.0]
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) [spring-tx-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.flowable.common.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:46) [flowable-spring-common-6.4.0.jar:6.4.0]
    at org.flowable.common.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30) [flowable-engine-common-6.4.0.jar:6.4.0]
    at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:56) [flowable-engine-common-6.4.0.jar:6.4.0]
    at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:51) [flowable-engine-common-6.4.0.jar:6.4.0]
Ravindra Gupta
  • 1,256
  • 12
  • 42

1 Answers1

1

The NPE that you have has nothing to do with suspending the task. I don’t know how you have the runtimeService defined in your UserWorkflowTaskListener. If you are autowiring it then you should not use class delegate for your listener. If you use class delegate Flowable will instantiate the class for you, it won’t go via the Spring dependency injection. You could either use a delegate expression or a normal expression to access your bean or access the runtime service via CommandContextUtil.getProcessEngineConfiguration().getRuntimeService()

Filip
  • 19,269
  • 7
  • 51
  • 60