NullPointerException when using a subprocess with a parameter with logging put to the maximum

Description

I get a NullPointerException when calling a subprocess with a parameter and when the logging is configured to FULL.

Pay attention ! All these 3 criteria must be met if you want to reproduce the problem. If you lower the logging, then there is no problem.

I have put a small project with unit test in attach that reproduces the problem.

Cause can be found in the class HistoryParseListener in the method:

public static int determineHistoryLevel(ScopeImpl scopeElement, int historyLevel) {
ProcessDefinitionImpl processDefinition = scopeElement.getProcessDefinition();
if (processDefinition != null) {
Integer processHistoryLevel = ((ProcessDefinitionEntity) processDefinition).getHistoryLevel();
if (processHistoryLevel != null) {
return Math.min(historyLevel, ((ProcessDefinitionEntity) scopeElement.getProcessDefinition()).getHistoryLevel());
}
}
return historyLevel;
}

The scopeElement is null if it concerns a subprocess, so on the firstline a NullPointer will be thrown.
The real cause of the problem can be found in the ExecutionEntity in the method:

public PvmProcessInstance createSubProcessInstance(PvmProcessDefinition processDefinition)

The problem is that a new ExecutionEntity is created but no activiti is set. Is you have a look at the method createExecution (in the same class) you can see that an activiti is attached.

This activiti (which is null) in the ExecutionEntity of the SubProcess will be passed as a parameter in several methods.
It will arrive in the method determineHistoryLevel where it will be passed to the scopeElement variable.

I was able to fix the problem by adding following code:

public PvmProcessInstance createSubProcessInstance(PvmProcessDefinition processDefinition) {
ExecutionEntity subProcessInstance = newExecution();

// manage bidirectional super-subprocess relation
subProcessInstance.setSuperExecution(this);
this.setSubProcessInstance(subProcessInstance);

// Initialize the new execution
subProcessInstance.setProcessDefinition((ProcessDefinitionImpl) processDefinition);
------>>>>>>>> subProcessInstance.setActivity(processDefinition.getInitialActivityStack().get(0));
subProcessInstance.setProcessInstance(subProcessInstance);

CommandContext commandContext = CommandContext.getCurrent();
int historyLevel = commandContext.getProcessEngineConfiguration().getHistoryLevel();
if (historyLevel>=ProcessEngineConfigurationImpl.HISTORYLEVEL_ACTIVITY) {
DbSqlSession dbSqlSession = commandContext.getSession(DbSqlSession.class);
HistoricProcessInstanceEntity historicProcessInstance = new HistoricProcessInstanceEntity((ExecutionEntity) subProcessInstance);
dbSqlSession.insert(historicProcessInstance);
}

return subProcessInstance;
}

It may be tricky to use .get(0) but since you are in a subprocess this will always result in the startEvent.

I have included a testproject !

Feel free to contact me ...

tom.stroobants@telenet.be

Environment

None

Assignee

Unassigned

Reporter

Tom Stroobants

Labels

None

Components

Affects versions

Priority

Minor
Configure