Bug 1032206

Summary: NPE when accessing tasks using a RuntimeEngine without persistence.
Product: [Retired] JBoss BPMS Platform 6 Reporter: Marek Baluch <mbaluch>
Component: jBPM CoreAssignee: Maciej Swiderski <mswiders>
Status: CLOSED CURRENTRELEASE QA Contact: Jiri Svitak <jsvitak>
Severity: medium Docs Contact:
Priority: high    
Version: 6.0.0CC: kverlaen, mbaluch
Target Milestone: ER6   
Target Release: 6.0.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-08-06 20:06:52 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Marek Baluch 2013-11-19 17:32:54 UTC
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>

Comment 1 Maciej Swiderski 2013-11-20 10:19:43 UTC
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?

Comment 2 Marek Baluch 2013-11-20 13:33:10 UTC
Maciej,

I believe that would be a fitting solution. Something like UnsupportedOperationException with a message explaining why it's not supported.

@mb

Comment 3 Maciej Swiderski 2013-11-21 10:34:15 UTC
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

Comment 4 Jiri Svitak 2014-01-03 11:57:14 UTC
Verified in BPMS 6 ER7 (6.0.1-redhat-2).