AnsweredAssumed Answered

NPE on variables get from ProcessInstance loaded via ProcessInstanceQuery

Question asked by mmaker1234 on Jun 21, 2013
Latest reply on Nov 4, 2015 by erikwinlof
Hello Activiti developers,

While executing in Activiti 5.13<java start="488" fancy="6">  ProcessInstance process = runtimeService.createProcessInstanceQuery()
                                    .processInstanceId( "1234" )
                                    .includeProcessVariables()
                                    .singleResult();
  if( process != null ) {
    Map<String, Object> vars = process.getProcessVariables(); //Throws NPE in ByteArrayRef.java:94
    …
  }</java>I observe the following error
java.lang.NullPointerException
    at org.activiti.engine.impl.persistence.entity.ByteArrayRef.ensureInitialized(ByteArrayRef.java:94)
    at org.activiti.engine.impl.persistence.entity.ByteArrayRef.getBytes(ByteArrayRef.java:45)
    at org.activiti.engine.impl.persistence.entity.VariableInstanceEntity.getBytes(VariableInstanceEntity.java:138)
    at org.activiti.engine.impl.variable.ByteArrayType.getValue(ByteArrayType.java:32)
    at org.activiti.engine.impl.variable.SerializableType.getValue(SerializableType.java:51)
    at org.activiti.engine.impl.persistence.entity.VariableInstanceEntity.getValue(VariableInstanceEntity.java:165)
    at org.activiti.engine.impl.persistence.entity.ExecutionEntity.getProcessVariables(ExecutionEntity.java:1384)
    at org.activiti.engine.impl.ant.ShowProcessState.formatProcessInstance(ShowProcessState.java:493)

I tried to debug and found that
Context.getCommandContext()
returns
null
in
ByteArrayRef.java:94
.

A similar code that passes the same row (
ByteArrayRef.java:94
) runs fine:<java start="488" fancy="6">  List<Execution> executions = runtimeService.createExecutionQuery()
                                    .processInstanceId( "1234" )
                                    .list();
  if( executions != null ) {
    for (Execution execution : executions) {
      Map<String, Object> globalVars = runtimeService.getVariables( execution.getId() );
      if( globalVars != null ) {
        …
      }
    }
  }</java>

Am I doing something wrong?

Outcomes