NPE in listPage query

We are using the flowable engine (6.2) embedded and see occasional NPE with the below stack when we attempt to list process instances including process variables and another thread happens to delete the process instance at the time this is being run.

Any suggestions on how to handle this?

Thanks

runtimeService
            .createProcessInstanceQuery().active()
                .includeProcessVariables().listPage(firstResult, maxResults);

This happens only when one or more process instances is deleted in another thread while the code is executing, as the variable and process has been deleted/completed.

Full Stack:
java.lang.NullPointerException: null
at org.flowable.variable.service.impl.persistence.entity.VariableByteArrayRef.ensureInitialized(VariableByteArrayRef.java:100)
at org.flowable.variable.service.impl.persistence.entity.VariableByteArrayRef.getBytes(VariableByteArrayRef.java:52)
at org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntityImpl.getBytes(VariableInstanceEntityImpl.java:108)
at org.flowable.variable.service.impl.types.ByteArrayType.getValue(ByteArrayType.java:37)
at org.flowable.variable.service.impl.types.SerializableType.getValue(SerializableType.java:62)
at org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntityImpl.getValue(VariableInstanceEntityImpl.java:133)
at org.flowable.variable.service.impl.persistence.entity.VariableInitializingList.initializeVariable(VariableInitializingList.java:66)
at org.flowable.variable.service.impl.persistence.entity.VariableInitializingList.add(VariableInitializingList.java:41)
at org.flowable.variable.service.impl.persistence.entity.VariableInitializingList.add(VariableInitializingList.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:1065)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyNestedResultMappings(DefaultResultSetHandler.java:909)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:849)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForNestedResultMap(DefaultResultSetHandler.java:825)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:311)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:286)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:183)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64)
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:324)
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:83)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
… 160 common frames omitted

Wrapped by: 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:150)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
        at org.flowable.engine.common.impl.db.DbSqlSession.selectListWithRawParameter(DbSqlSession.java:202)
        at org.flowable.engine.common.impl.db.DbSqlSession.selectListWithRawParameterNoCacheCheck(DbSqlSession.java:179)
        at org.flowable.engine.impl.persistence.entity.data.impl.MybatisExecutionDataManager.findProcessInstanceAndVariablesByQueryCriteria(MybatisExecutionDataManager.j
ava:272)
        at org.flowable.engine.impl.persistence.entity.ExecutionEntityManagerImpl.findProcessInstanceAndVariablesByQueryCriteria(ExecutionEntityManagerImpl.java:193)
        at org.flowable.engine.impl.ProcessInstanceQueryImpl.executeList(ProcessInstanceQueryImpl.java:697)
        at org.flowable.engine.common.impl.AbstractQuery.execute(AbstractQuery.java:147)
        at org.flowable.engine.impl.interceptor.CommandInvoker$1.run(CommandInvoker.java:51)
        at org.flowable.engine.impl.interceptor.CommandInvoker.executeOperation(CommandInvoker.java:93)
        at org.flowable.engine.impl.interceptor.CommandInvoker.executeOperations(CommandInvoker.java:72)
        at org.flowable.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:56)
        at org.flowable.engine.impl.interceptor.BpmnOverrideContextInterceptor.execute(BpmnOverrideContextInterceptor.java:25)
        at org.flowable.engine.common.impl.interceptor.TransactionContextInterceptor.execute(TransactionContextInterceptor.java:53)
        at org.flowable.engine.common.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:72)
        at org.flowable.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:49)
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
        at org.flowable.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:46)
        at org.flowable.engine.common.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30)
        at org.flowable.engine.common.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:56)
        at org.flowable.engine.common.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:51)
        at org.flowable.engine.common.impl.AbstractQuery.listPage(AbstractQuery.java:126)
...

Did you get any further with this issue?

I see it happening in Flowable 6.4 when a process ends at the same time as the query takes place. I presume it is because the RU tables are being vacated and entries moved to HI tables in the middle of the initialization of VariableByteArrayRef.

Can you describe when exactly you see this happening? The situation you describe only happens at the end of any service operation (when the data is flushed), so I’m wondering which kind of usage you have.

I have a process instance running asynchronously and external service polling by business key for the outcome of the process instance.

our use case is similar too, if another thread tries to do listPage while a different thread is deleting the process instance, this can happen.

We’re using MySQL - the issue only occurs when tx isolation is set to READ_COMMITTED. In REPEATABLE_READ we’re not able to reproduce it.

Looking at the stacktrace, it seems like the entity coming back from the findById() call is not there anymore. What happens is that transaction 1 has deleted the bytes in the moment just before the list call of the transaction 2 is fetching the variable bytes (after it already called the list of variables, but not yet the bytes).

Fixed the NPE here: https://github.com/flowable/flowable-engine/commit/df505854e8c6cf90c3069aa23d5c991c7f4be069

1 Like