ZPY博客

activiti7监听器listener中执行报错Exception while invoking TaskListener: null

activiti7监听器listener中执行时老是报错,具体报错信息如下:

2020-02-25 10:31:32.562 ERROR 24684 --- [ main] o.a.e.impl.interceptor.CommandContext : Error while closing command context

org.activiti.engine.ActivitiException: Exception while invoking TaskListener: Exception while invoking TaskListener: null
at org.activiti.engine.impl.bpmn.listener.ListenerNotificationHelper.executeTaskListeners(ListenerNotificationHelper.java:124) ~[activiti-engine-7.1.0.M6.jar:na]
at org.activiti.engine.impl.bpmn.listener.ListenerNotificationHelper.executeTaskListeners(ListenerNotificationHelper.java:104) ~[activiti-engine-7.1.0.M6.jar:na]
at org.activiti.engine.impl.cmd.AbstractCompleteTaskCmd.executeTaskComplete(AbstractCompleteTaskCmd.java:48) ~[activiti-engine-7.1.0.M6.jar:na]
at org.activiti.engine.impl.cmd.CompleteTaskCmd.execute(CompleteTaskCmd.java:69) ~[activiti-engine-7.1.0.M6.jar:na]
at org.activiti.engine.impl.cmd.CompleteTaskCmd.execute(CompleteTaskCmd.java:24) ~[activiti-engine-7.1.0.M6.jar:na]
at org.activiti.engine.impl.cmd.NeedsActiveTaskCmd.execute(NeedsActiveTaskCmd.java:56) ~[activiti-engine-7.1.0.M6.jar:na]
at org.activiti.engine.impl.interceptor.CommandInvoker$1.run(CommandInvoker.java:37) ~[activiti-engine-7.1.0.M6.jar:na]
at org.activiti.engine.impl.interceptor.CommandInvoker.executeOperation(CommandInvoker.java:78) ~[activiti-engine-7.1.0.M6.jar:na]
at org.activiti.engine.impl.interceptor.CommandInvoker.executeOperations(CommandInvoker.java:57) ~[activiti-engine-7.1.0.M6.jar:na]
at org.activiti.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:42) ~[activiti-engine-7.1.0.M6.jar:na]
at org.activiti.engine.impl.interceptor.TransactionContextInterceptor.execute(TransactionContextInterceptor.java:48) ~[activiti-engine-7.1.0.M6.jar:na]
at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:59) ~[activiti-engine-7.1.0.M6.jar:na]
at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:47) [activiti-spring-7.1.0.M6.jar:na]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) [spring-tx-5.1.13.RELEASE.jar:5.1.13.RELEASE]
at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:45) [activiti-spring-7.1.0.M6.jar:na]
at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:29) [activiti-engine-7.1.0.M6.jar:na]
at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:44) [activiti-engine-7.1.0.M6.jar:na]
at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:39) [activiti-engine-7.1.0.M6.jar:na]
at org.activiti.engine.impl.TaskServiceImpl.complete(TaskServiceImpl.java:202) [activiti-engine-7.1.0.M6.jar:na]
at org.activiti.runtime.api.impl.TaskRuntimeImpl.complete(TaskRuntimeImpl.java:160) [activiti-api-task-runtime-impl-7.1.0.M6.jar:na]
at org.activiti.runtime.api.impl.TaskRuntimeImpl$$FastClassBySpringCGLIB$$cb179e94.invoke(<generated>) [activiti-api-task-runtime-impl-7.1.0.M6.jar:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) [spring-core-5.1.13.RELEASE.jar:5.1.13.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:750) [spring-aop-5.1.13.RELEASE.jar:5.1.13.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) [spring-aop-5.1.13.RELEASE.jar:5.1.13.RELEASE]
at org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:69) [spring-security-core-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.1.13.RELEASE.jar:5.1.13.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689) [spring-aop-5.1.13.RELEASE.jar:5.1.13.RELEASE]
at org.activiti.runtime.api.impl.TaskRuntimeImpl$$EnhancerBySpringCGLIB$$8cbc41b4.complete(<generated>) [activiti-api-task-runtime-impl-7.1.0.M6.jar:na]
at com.zp.activitispringboot.utils.ActivitiUtil.completeTaskWithVariables(ActivitiUtil.java:154) [classes/:na]
at com.zp.activitispringboot.HuiqianTest.testCompleteTask2(HuiqianTest.java:76) [test-classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_171]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_171]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_171]
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) [junit-4.12.jar:4.12]
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.12.jar:4.12]
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) [junit-4.12.jar:4.12]
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) [junit-4.12.jar:4.12]
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74) [spring-test-5.1.13.RELEASE.jar:5.1.13.RELEASE]
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84) [spring-test-5.1.13.RELEASE.jar:5.1.13.RELEASE]
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) [spring-test-5.1.13.RELEASE.jar:5.1.13.RELEASE]
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) [spring-test-5.1.13.RELEASE.jar:5.1.13.RELEASE]
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) [spring-test-5.1.13.RELEASE.jar:5.1.13.RELEASE]
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) [junit-4.12.jar:4.12]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251) [spring-test-5.1.13.RELEASE.jar:5.1.13.RELEASE]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) [spring-test-5.1.13.RELEASE.jar:5.1.13.RELEASE]
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) [junit-4.12.jar:4.12]
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) [junit-4.12.jar:4.12]
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) [junit-4.12.jar:4.12]
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) [junit-4.12.jar:4.12]
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) [junit-4.12.jar:4.12]
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) [spring-test-5.1.13.RELEASE.jar:5.1.13.RELEASE]
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) [spring-test-5.1.13.RELEASE.jar:5.1.13.RELEASE]
at org.junit.runners.ParentRunner.run(ParentRunner.java:363) [junit-4.12.jar:4.12]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) [spring-test-5.1.13.RELEASE.jar:5.1.13.RELEASE]
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460) [.cp/:na]
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206) [.cp/:na]
Caused by: org.activiti.engine.ActivitiException: Exception while invoking TaskListener: null
at org.activiti.engine.impl.bpmn.helper.ClassDelegate.notify(ClassDelegate.java:140) ~[activiti-engine-7.1.0.M6.jar:na]
at org.activiti.engine.impl.delegate.invocation.TaskListenerInvocation.invoke(TaskListenerInvocation.java:34) ~[activiti-engine-7.1.0.M6.jar:na]
at org.activiti.engine.impl.delegate.invocation.DelegateInvocation.proceed(DelegateInvocation.java:35) ~[activiti-engine-7.1.0.M6.jar:na]
at org.activiti.engine.impl.delegate.invocation.DefaultDelegateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:25) ~[activiti-engine-7.1.0.M6.jar:na]
at org.activiti.engine.impl.bpmn.listener.ListenerNotificationHelper.executeTaskListeners(ListenerNotificationHelper.java:122) ~[activiti-engine-7.1.0.M6.jar:na]
... 60 common frames omitted
Caused by: java.lang.NullPointerException: null
at com.zp.activitispringboot.listener.SignListener.notify(SignListener.java:52) ~[classes/:na]
at org.activiti.engine.impl.delegate.invocation.TaskListenerInvocation.invoke(TaskListenerInvocation.java:34) ~[activiti-engine-7.1.0.M6.jar:na]
at org.activiti.engine.impl.delegate.invocation.DelegateInvocation.proceed(DelegateInvocation.java:35) ~[activiti-engine-7.1.0.M6.jar:na]
at org.activiti.engine.impl.delegate.invocation.DefaultDelegateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:25) ~[activiti-engine-7.1.0.M6.jar:na]
at org.activiti.engine.impl.bpmn.helper.ClassDelegate.notify(ClassDelegate.java:138) ~[activiti-engine-7.1.0.M6.jar:na]
... 64 common frames omitted

定位到出问题的是runtimeService.getVariable(exId, "pass");这一行,但是我debug看了下无论是runtimeService对象还是exId都不是null,那怎么会报空指针异常呢?百度了下也没有找到相关的问题。。初步怀疑是runtimeService.getVariable这个函数的问题。搜索监听器里获取流程变量时发现不止runtimeService中有getVariable函数,taskService中也有getVariable这个函数,于是抱着试一试的心态换成了taskService.getVariable,于是问题就解决了!!!
如果有遇到这个问题的,不妨试试。