Sorry but I don't understand your answer.
I recurrently throws this error when I work with WorkflowProcessInstance.
This is the code that failed :
WorkflowProcessInstance wpi = (WorkflowProcessInstance)kSession.getProcessInstance(processInstanceId);
wpi.setVariable(key, object);
or
WorkflowProcessInstance wpi = (WorkflowProcessInstance)kSession.getProcessInstance(processInstanceId);
if((wpi == null) || (wpi.getVariable(key) == null)){
//This case never appears because of persistent sessions
System.out.println("workflow process instance is null :-(");
}else{
System.out.println("workflow process instance is NOT null :-)");
retObj = wpi.getVariable(key);
//node info
System.out.println("list of node instance : ");
for(NodeInstance iNode : wpi.getNodeInstances()){
Node node = iNode.getNode();
}
}