AnsweredAssumed Answered

NullPointerException in ExecutionEntity

Question asked by iravanchi on Sep 29, 2010
Latest reply on Oct 1, 2010 by jbarrez
Hi,

I want to display a list of running process instances in my UI, and here's what I did:

Called runtimeService.createProcessInstanceQuery().list();
For each of them
{
    called repositoryService.findProcessDefinitionById(processInstance.getProcessDefinitionId()) to get the definition name.
    called processInstance.findActiveActivityIds()
}

In the last line, I get an exception as follows:

Caused by: java.lang.NullPointerException
   at org.activiti.engine.impl.runtime.ExecutionEntity.ensureProcessDefinitionInitialized(ExecutionEntity.java:195)
   at org.activiti.pvm.impl.runtime.ExecutionImpl.getProcessDefinition(ExecutionImpl.java:296)
   at org.activiti.engine.impl.runtime.ExecutionEntity.ensureActivityInitialized(ExecutionEntity.java:235)
   at org.activiti.pvm.impl.runtime.ExecutionImpl.collectActiveActivityIds(ExecutionImpl.java:274)
   at org.activiti.pvm.impl.runtime.ExecutionImpl.findActiveActivityIds(ExecutionImpl.java:269)
   …

Note: this was the first thing requested from the engine when the process is run.
By looking at the code, I guess this happens when the process definition is loaded in a way that doesn't parse the process definition. When we call findActiveActivityIds it tries to load and parse the definition too. I guess (I'm not sure) that CommandContext.getCurrent() is returning null when called in this context.

Should I add this to JIRA?
And is there a better way to do what I was doing originally?

Outcomes