Multi instance Task query bpmnAggregation variable throw NullPointException

The multi instance task in a subprocess which have a timer boudary event, I create a aggregation variables in my multi instance task which set as overview variables. After timer fire, the subprocess cancelled, and I query the process with historyService.createHistoricProcessInstanceQuery().processInstanceId(processId).includeProcessVariables().singleResult(); always throw null proint excelption.

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.NullPointerException
### Cause: java.lang.NullPointerException

	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
	at org.flowable.common.engine.impl.db.DbSqlSession.selectListWithRawParameter(DbSqlSession.java:271)
	at org.flowable.common.engine.impl.db.DbSqlSession.queryWithRawParameter(DbSqlSession.java:250)
	at org.flowable.common.engine.impl.db.DbSqlSession.selectList(DbSqlSession.java:165)
	at org.flowable.engine.impl.persistence.entity.data.impl.MybatisHistoricProcessInstanceDataManager.findHistoricProcessInstancesAndVariablesByQueryCriteria(MybatisHistoricProcessInstanceDataManager.java:80)
	at org.flowable.engine.impl.persistence.entity.HistoricProcessInstanceEntityManagerImpl.findHistoricProcessInstancesAndVariablesByQueryCriteria(HistoricProcessInstanceEntityManagerImpl.java:64)
	at org.flowable.engine.impl.HistoricProcessInstanceQueryImpl.executeList(HistoricProcessInstanceQueryImpl.java:957)
	at org.flowable.common.engine.impl.query.AbstractQuery.executeSingleResult(AbstractQuery.java:180)
	at org.flowable.common.engine.impl.query.AbstractQuery.execute(AbstractQuery.java:164)
	at org.flowable.engine.impl.interceptor.CommandInvoker$1.run(CommandInvoker.java:67)
	at org.flowable.engine.impl.interceptor.CommandInvoker.executeOperation(CommandInvoker.java:140)
	at org.flowable.engine.impl.interceptor.CommandInvoker.executeOperations(CommandInvoker.java:114)
	at org.flowable.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:72)
	at org.flowable.engine.impl.interceptor.BpmnOverrideContextInterceptor.execute(BpmnOverrideContextInterceptor.java:26)
	at org.flowable.common.engine.impl.interceptor.TransactionContextInterceptor.execute(TransactionContextInterceptor.java:53)
	at org.flowable.common.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:105)
	at org.flowable.common.spring.SpringTransactionInterceptor.lambda$execute$0(SpringTransactionInterceptor.java:57)
	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
	at org.flowable.common.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:57)
	at org.flowable.common.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30)
	at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:56)
	at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:51)
	at org.flowable.common.engine.impl.query.AbstractQuery.singleResult(AbstractQuery.java:105)
	at com.lianpay.zx.workflow.service.impl.ProcessServiceImpl.getVarsByProcessId(ProcessServiceImpl.java:84)
	at com.lianpay.zx.ReviewConfigTests.testCreateFlow(ReviewConfigTests.java:115)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:686)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)
	at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:212)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:208)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:137)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:71)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:248)
	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$5(DefaultLauncher.java:211)
	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:226)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:199)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:132)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: java.lang.NullPointerException
	at org.flowable.engine.impl.variable.BpmnAggregation.aggregateOverview(BpmnAggregation.java:140)
	at org.flowable.engine.impl.variable.BpmnAggregatedVariableType.getValue(BpmnAggregatedVariableType.java:67)
	at org.flowable.variable.service.impl.persistence.entity.HistoricVariableInstanceEntityImpl.getValue(HistoricVariableInstanceEntityImpl.java:88)
	at org.flowable.variable.service.impl.persistence.entity.HistoricVariableInitializingList.initializeVariable(HistoricVariableInitializingList.java:66)
	at org.flowable.variable.service.impl.persistence.entity.HistoricVariableInitializingList.add(HistoricVariableInitializingList.java:41)
	at org.flowable.variable.service.impl.persistence.entity.HistoricVariableInitializingList.add(HistoricVariableInitializingList.java:29)
	at org.apache.ibatis.reflection.wrapper.CollectionWrapper.add(CollectionWrapper.java:93)
	at org.apache.ibatis.reflection.MetaObject.add(MetaObject.java:158)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.linkObjects(DefaultResultSetHandler.java:1105)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyNestedResultMappings(DefaultResultSetHandler.java:954)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:421)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForNestedResultMap(DefaultResultSetHandler.java:909)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:326)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:301)
	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:194)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:65)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)
	at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63)
	at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325)
	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)
	... 90 more

How to query process without exception?

Best Regards!

@nealsun I’ve tried to reproduce the problem but my tests are working properly.

Can you please share an example model that has this problem?

Thanks,
Filip

@filiphr Thank for your reply. I set my boundary event timer cancelActivity="true", is ti matters? when i changed this params to false, the exception is gone and the process can walk through the process flow to the end event, but the process is not end, why?

@nealsun have a look at Add test for overview variable aggregations with a timer boundary event · flowable/flowable-engine@e01f8cb · GitHub. This is a test case that I came up from your example and it is green.

Can you please share your BPMN XML file so that we can try it out?

Cheers,
Filip

@filiphr because of my model have many listeners and expressions, I modify the example you provided, and the exception throws. Mitask in the subprocess and timer boundary event attached to subprocess. I just paste below

<?xml version="1.0" encoding="UTF-8"?>
<definitions id="definition"
             xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:flowable="http://flowable.org/bpmn"
             targetNamespace="Examples">

    <process id="myProcess">

        <startEvent id="theStart" />
        <sequenceFlow id="flow1" sourceRef="theStart" targetRef="theSubProcess" />
        <subProcess id="theSubProcess">


            <startEvent id="subStart"  />
            <sequenceFlow id="subflow0" sourceRef="subStart" targetRef="miTasks" />

            <userTask id="miTasks" name="My Task" flowable:taskIdVariableName="taskId" flowable:priority="${loopCounter}">

                <multiInstanceLoopCharacteristics isSequential="false">
                    <extensionElements>
                        <flowable:variableAggregation target="reviews" createOverviewVariable="true">
                            <variable sourceExpression="${task:get(taskId).assignee}" target="userId" />
                            <variable source="approved"  />
                            <variable source="description" />
                        </flowable:variableAggregation>
                    </extensionElements>
                    <loopCardinality>${nrOfLoops}</loopCardinality>
                </multiInstanceLoopCharacteristics>

            </userTask>
            <sequenceFlow id="subflow1" sourceRef="miTasks" targetRef="subEnd" />

            <endEvent id="subEnd" />

        </subProcess>

        <boundaryEvent id="boundary" name="Timer" attachedToRef="theSubProcess" cancelActivity="true">
            <timerEventDefinition>
                <timeDuration>PT10H</timeDuration>
            </timerEventDefinition>
        </boundaryEvent>

        <sequenceFlow id="flow4" sourceRef="theSubProcess" targetRef="afterMiTasks" />
        <userTask id="afterMiTasks" />

        <sequenceFlow id="flow6" sourceRef="boundary" targetRef="afterBoundary" />
        <userTask id="afterBoundary" />

        <sequenceFlow id="flow5" sourceRef="afterMiTasks" targetRef="theEnd" />
        <sequenceFlow id="flow7" sourceRef="afterBoundary" targetRef="theEnd" />
        <endEvent id="theEnd" />

    </process>

</definitions>