cancel
Showing results for 
Search instead for 
Did you mean: 

NPE retrieving a blob local task variable

hyapit
Champ in-the-making
Champ in-the-making
Hi guys,

I'm getting a NullPointerException executing HistoricTaskInstance.getTaskLocalVariables() when I have a task variables with blobs as their values. This is 5.13

It seems like Context.getCommandContext() returns null, because the context threadlocal is not set for executing thread. Is this expected or a bug? Advice?

Here's the stack trace:
java.lang.NullPointerException
   at org.activiti.engine.impl.persistence.entity.ByteArrayRef.ensureInitialized(ByteArrayRef.java:94)
   at org.activiti.engine.impl.persistence.entity.ByteArrayRef.getBytes(ByteArrayRef.java:45)
   at org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity.getBytes(HistoricVariableInstanceEntity.java:119)
   at org.activiti.engine.impl.variable.ByteArrayType.getValue(ByteArrayType.java:32)
   at org.activiti.engine.impl.variable.SerializableType.getValue(SerializableType.java:51)
   at org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity.getValue(HistoricVariableInstanceEntity.java:110)
   at org.activiti.engine.impl.persistence.entity.HistoricTaskInstanceEntity.getTaskLocalVariables(HistoricTaskInstanceEntity.java:172)

This is where it's throwing NPE:
private void ensureInitialized() {
    if (id != null && entity == null) {
      entity = Context.getCommandContext()
        .getByteArrayEntityManager()
        .findById(id);
      name = entity.getName();
    }
  }
2 REPLIES 2

hyapit
Champ in-the-making
Champ in-the-making
Any thoughts guys?

frederikherema1
Star Contributor
Star Contributor
You can only use HistoricTaskInstance.getXXXVqariables() when you have done a historic task-query requested to include the variables, as the API states: /** Returns the process variables if requested in the task query */
There is an issue in the 5.13 release related to this functionality for non-historic tasks (https://jira.codehaus.org/browse/ACT-1731). I'll make sure the historic variables get fixed as well as part of this work.