cancel
Showing results for 
Search instead for 
Did you mean: 

activitiUtil.getProcessInstance(instanceId) returns null

tullo1
Champ in-the-making
Champ in-the-making
Hi

I try to start the ootb adhoc workflow from within a service task in alfresco.

When the service task is triggered the method call activitiUtil.getProcessInstance(instanceId) will always return null for an instanceId mapped to the adhoc worflow just started. 

ActivitiTypeConverter

public WorkflowPath convert(Execution execution)
{
    String instanceId = execution.getProcessInstanceId();
    ProcessInstance instance = activitiUtil.getProcessInstance(instanceId);
    return convert(execution, instance);
}


Could that be a transaction related problem?

BR
Andreas
13 REPLIES 13

ismaelgarcia
Champ in-the-making
Champ in-the-making
We are having the same problem with Alfresco 4.2.f (Activiti 5.13-alf-20130918). We start a new WF in a Alfresco ScriptTask and we are having the same NPE at the line:

Caused by: java.lang.NullPointerException
at org.alfresco.repo.workflow.activiti.ActivitiTypeConverter.convert(ActivitiTypeConverter.java:300)

We are planning the upgrade from 4.0e and have arround 2000 active workflows, so we cannot change the way the workflows are started in the active workflows.

We have created a minimal workflow to reproduce the behaviour, (WFTEST.bpmn), that has only one task and start an alfresco ootb adhoc workflow.

So far we have tested:
- Change the start workflow script for a Java service task (for testing purpose) and the error persist.
- Change the start workflow script for a Java service task (for testing purpose) and start the workflow using an new thread. The new workflow is started.

Regarding other alfresco versions:
- In Alfresco 4.2.a (Activiti 5.10), the script task is working, and the new workflow is started.
- In Alfresco 4.2.b (Activiti 5.10), the script task is working, , and the new workflow is started.
- In Alfresco 4.2.c (Activiti 5.10-14112012), Alfresco throws an error when we try to start WFTEST (maybe another alfresco bug)
- In Alfresco 4.2.d (Activiti 5.13-alf-20130709), the same error as in 4.2.f
- In Alfresco 4.2.e (Activiti 5.13-alf-20130918), the same error as in 4.2.f

We have also tryied the lastest activiti-alfresco version (5.13-alf-20140708) with Alfresco 4.2f without luck.

The log attached is generated by activating debug in alfresco/WEB-INF/classes/log4j.properties :
log4j.logger.org.alfresco.repo.jscript=debug
log4j.logger.org.alfresco.repo.jscript.ScriptLogger=debug
log4j.logger.org.activiti.engine=debug

Has anyone any guide to solve the problem?

Thanks in advance!

frederikherema1
Star Contributor
Star Contributor
The processInstance that is passed to the convert(execution, instance) method, is fetched using the folowing code:


ProcessInstance instance = activitiUtil.getProcessInstance(instanceId);
        return convert(execution, instance);

I think the issue lies in the transaction/connection. The activitiUtil will query for a process instance based on id, ignoring the fact that the ProcessInstance entity is the execution itself. However, that entity is not yet committed in the DB, only flushed to the current open transaction. What is the transaction isolation level? Has is changed between the version of alfresco you used for testing?

If you're running a custom build of Alfresco, you can try to replace the offending convert method with the following, which actually prevent a query in case the execution IS a process-instance.

public WorkflowPath convert(Execution execution)
    {
        ProcessInstance instance;
        String instanceId = execution.getProcessInstanceId();
        if(instanceId.equals(execution.getId()) {
            instance = (ProcessInstance) execution;
        } else {
            instance = activitiUtil.getProcessInstance(instanceId);
        }
        return convert(execution, instance);
    }

ismaelgarcia
Champ in-the-making
Champ in-the-making
Hi,

Thanks for the quick answer.. I already found another solution that works. Mabybe yours is better.. I'll try your aproach later.

I compared the activiti-afresco 5.13 with 5.10 to see what has changed and found in activiti-engine that the class:

<code>org/activiti/engine/impl/interceptor/CommandContextInterceptor.java</code>

now reuses the context to execute the commands and the old version (5.10 series) creates a new one always.

So, I changed this class to be as it was in 5.10 and now all the workflow creation issue is gone!

I don't know if this change may affect anything else. I've researched in github and found that this change was made in version 5.11, related to the improvement http://jira.codehaus.org/browse/ACT-1387.

My solution involves recompiling activiti-engine, and yours involes recompiling alfresco-repository.

I'll try your solution also, thanks,

Ismael Garcia

ismaelgarcia
Champ in-the-making
Champ in-the-making
frederikheremans,

I tried yout approach without luck…

After changing the "convert" function, the error is produced in :

<code>
Caused by: java.lang.NullPointerException
        at org.alfresco.repo.workflow.activiti.ActivitiTypeConverter.convertToInstanceAndSetVariables(ActivitiTypeConverter.java:804)
        at org.alfresco.repo.workflow.activiti.ActivitiTypeConverter.convertAndSetVariables(ActivitiTypeConverter.java:260)
        at org.alfresco.repo.workflow.activiti.ActivitiTypeConverter.convert(ActivitiTypeConverter.java:307)
        at org.alfresco.repo.workflow.activiti.ActivitiTypeConverter.convert(ActivitiTypeConverter.java:295)
        at org.alfresco.repo.workflow.activiti.ActivitiWorkflowEngine.startWorkflow(ActivitiWorkflowEngine.java:995)
        at org.alfresco.repo.workflow.WorkflowServiceImpl.startWorkflow(WorkflowServiceImpl.java:438)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
</code>

because in the method :

<java>
    public WorkflowInstance convertAndSetVariables(ProcessInstance instance, Map<String, Object> collectedvariables)
    {
        if(instance == null)
            return null;
       
        HistoricProcessInstance historicInstance = historyService
         .createHistoricProcessInstanceQuery()
         .processInstanceId(instance.getId())
         .singleResult();
       
       return convertToInstanceAndSetVariables(historicInstance, collectedvariables);
    }
</java>

The "historicInstance" variable is null. I think it's caused by the same reason originally the variable "instance" was null in the "convert" method. Something related to transactions. Maybe the final solution must involve some work in the transaction level..

Anyway, your solution prevents a query, which is good, but the problem persists a little futher.

It you have any new ideas, I will try them.

Thanks anyway!