Discussion:
[jboss-user] [jBPM] - calling the setVariable on reloaded ProcessInstance leads to NullPointerException
Oleg Bondarenko
2013-03-04 11:01:36 UTC
Permalink
Oleg Bondarenko [https://community.jboss.org/people/obon] created the discussion

"calling the setVariable on reloaded ProcessInstance leads to NullPointerException"

To view the discussion, visit: https://community.jboss.org/message/800555#800555

--------------------------------------------------------------
Hi,

at some point in my application I reload my session:

JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, config, env);

then my process instance:

WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.getProcessInstance(processInstanceId);

and then try to set a process variable:

processInstance.setVariable(name, value)

which fails :
java.lang.NullPointerException
    at org.jbpm.process.instance.impl.ProcessInstanceImpl.getProcess(ProcessInstanceImpl.java:68)
    at org.jbpm.process.instance.impl.ProcessInstanceImpl.getContextInstance(ProcessInstanceImpl.java:133)
    at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.setVariable(WorkflowProcessInstanceImpl.java:238)
    ...

The reason is: the variable InternalKnowledgeRuntime kruntime in ProcessInstanceImpl is null.

Is it a bug or is there another way to load the process instance?

Regards,
Oleg
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/800555#800555]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
amadets
2013-03-04 11:12:12 UTC
Permalink
amadets [https://community.jboss.org/people/amadets] created the discussion

"Re: calling the setVariable on reloaded ProcessInstance leads to NullPointerException"

To view the discussion, visit: https://community.jboss.org/message/800559#800559

--------------------------------------------------------------
I don't know that is a bug or not, but this not work properly.
Try this:
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.add(varName, varValue);
org.drools.runtime.process.ProcessInstance processInstance = ksession.createProcessInstance(processId, parameters);
ksession.startProcessInstance(processInstance.getId());   
WorkflowProcessInstance wpi = (WorkflowProcessInstance) processInstance;

ts
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/800559#800559]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Oleg Bondarenko
2013-03-04 11:21:42 UTC
Permalink
Oleg Bondarenko [https://community.jboss.org/people/obon] created the discussion

"Re: calling the setVariable on reloaded ProcessInstance leads to NullPointerException"

To view the discussion, visit: https://community.jboss.org/message/800562#800562

--------------------------------------------------------------
Thanks for the answer, but what you suggest is what I do to START a new process instance, but in my case I already have an existing prosess instance persisted in the database.

ButI am trying to RELOAD it, using the above mentioned API ( ksession.getProcessInstance(processInstanceId) ).

The kruntime field of ProcessInstanceImpl is for some reason declared transient, probably therefore it does not get initialized.

Why?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/800562#800562]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
amadets
2013-03-04 11:48:14 UTC
Permalink
amadets [https://community.jboss.org/people/amadets] created the discussion

"Re: calling the setVariable on reloaded ProcessInstance leads to NullPointerException"

To view the discussion, visit: https://community.jboss.org/message/800567#800567

--------------------------------------------------------------
ops, sorry i read carelessly.
it may be helpful:
docuemntation said:
+Returns the process instance with the given id. Note that only active process instances will be returned. If a process instance has been completed already, this method will return null.+

I noticed also that when kbase don't have process definition which instance try to load it also return null (in 5.4).+
+
ts+
+
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/800567#800567]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Oleg Bondarenko
2013-03-04 12:28:51 UTC
Permalink
Oleg Bondarenko [https://community.jboss.org/people/obon] created the discussion

"Re: calling the setVariable on reloaded ProcessInstance leads to NullPointerException"

To view the discussion, visit: https://community.jboss.org/message/800581#800581

--------------------------------------------------------------
as I pointed out, the problem is not because the returned active process instance null, but because it is not completely initialized.

The exception happens in the following method of the class org.jbpm.process.instance.impl.ProcessInstanceImpl:


| | public Process getProcess() { |
|     | if (this.process == null) { |
|         | this.process = kruntime.getKnowledgeBase().getProcess(processId); |
|     | } |
|     | return this.process; |
| | } |

The kruntime is null.

I hope, now the problem is clearly and completely described.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/800581#800581]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Oleg Bondarenko
2013-03-04 13:37:08 UTC
Permalink
Oleg Bondarenko [https://community.jboss.org/people/obon] created the discussion

"Re: calling the setVariable on reloaded ProcessInstance leads to NullPointerException"

To view the discussion, visit: https://community.jboss.org/message/800596#800596

--------------------------------------------------------------
got it.

wrap the whole thing in a transaction, also described here:

https://community.jboss.org/thread/199180 https://community.jboss.org/thread/199180
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/800596#800596]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Loading...