Description of problem: Following code will throw NPE when ts.getTasksByProcessInstance(pi.getId()); is called. <code-snip> public class JbpmExecutor { public RuntimeEngine newRuntime(String... processes) throws Exception { RuntimeEnvironmentBuilder builder = RuntimeEnvironmentBuilder.getEmpty() .addConfiguration("drools.processSignalManagerFactory", DefaultSignalManagerFactory.class.getName()) .addConfiguration("drools.processInstanceManagerFactory", DefaultProcessInstanceManagerFactory.class.getName()); for (String process : processes) { builder.addAsset(ResourceFactory.newClassPathResource(process), ResourceType.BPMN2); } // for (String ruleFile : ruleFiles) { // builder.addAsset(ResourceFactory.newClassPathResource(ruleFile), ResourceType.DRL); // } RuntimeManager manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(builder.get(), "Singleton " + UUID.randomUUID().toString()); RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get()); return runtime; } public static void main(String ... args) throws Exception { JbpmExecutor executor = new JbpmExecutor(); RuntimeEngine runtime = executor.newRuntime("xxx.bpmn2"); ProcessInstance pi = runtime.getKieSession().startProcess("BPMN2IntermediateThrowEscalationEvent"); System.out.println(pi.getState() == ProcessInstance.STATE_COMPLETED); TaskService ts = runtime.getTaskService(); // Throws NPE. I would consider this a bug which is not yet reported. System.out.println(ts.getTasksByProcessInstanceId(pi.getId())); } } </code-snip>
Marek, that is sort of expected behavior as you don't configure task service and thus it's not available. You use Empty builder which means you need to setup everything manually, while you could use DefaultInMemory to have task service configured and process engine in memory only. The improvement we could apply here is that it shall throw an exception on getTaskService method when it is not configured with meaningful message instead of NPE. Wdyt?
Maciej, I believe that would be a fitting solution. Something like UnsupportedOperationException with a message explaining why it's not supported. @mb
alright, exception is now thrown in case task service is not configured to avoid further NPE. jbpm master: https://github.com/droolsjbpm/jbpm/commit/66a00615ccb8ddc863e9f0023db209d9fd18e7d1 6.0.x: https://github.com/droolsjbpm/jbpm/commit/264f70ba67d045eb94a9b7c2a575fecf43196a6e
Verified in BPMS 6 ER7 (6.0.1-redhat-2).