cancel
Showing results for 
Search instead for 
Did you mean: 

NPE on historicVariableInstance.getValue

gokceng1
Champ in-the-making
Champ in-the-making
Hi,
I've a process definition which is consisting of service tasks so there is no wait state in it. After calling

startProcessInstanceByKey(processDefinitionKey, map);


process starts, ends and return. After returning, I'm trying to access a variable which I gave in the map parameter. The parameter I'm trying to access is a custom object implementing Serializable interface. I use that query:


   NativeHistoricVariableInstanceQuery historicVariableInstanceQuery = historyService.createNativeHistoricVariableInstanceQuery();
   historicVariableInstanceQuery.sql("SELECT * FROM " + managementService.getTableName(HistoricVariableInstance.class) +
         " WHERE EXECUTION_ID_=#{executionId} AND NAME_=#{variableName}");
   historicVariableInstanceQuery.parameter("executionId", executionId);
   historicVariableInstanceQuery.parameter("variableName", variableName);
   HistoricVariableInstance historicVariableInstance = historicVariableInstanceQuery.singleResult();
   if (historicVariableInstance != null) {
      return (T) historicVariableInstance.getValue();
   }
   return null;



At the line
return  (T) historicVariableInstance.getValue();
(SimpleActivitiQueryService.java:65) I get a NPE:


java.lang.NullPointerException
   at org.activiti.engine.impl.persistence.entity.ByteArrayRef.ensureInitialized(ByteArrayRef.java:93)
   at org.activiti.engine.impl.persistence.entity.ByteArrayRef.getBytes(ByteArrayRef.java:46)
   at org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity.getBytes(HistoricVariableInstanceEntity.java:123)
   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:114)
   at myPkg.SimpleActivitiQueryService.findLastValueOfVariable(SimpleActivitiQueryService.java:65)


It seems that at
ByteArrayRef.java:93
,
Context.getCommandContext()
is null.

I've seen some possibly related links but I'm not sure if they about this issue or not:
Thanks.
4 REPLIES 4

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

I created small jUnit test for it. - Result is the same. I will have a look on it.

https://github.com/martin-grofcik/Activiti/blob/forum-NPE/modules/activiti-engine/src/test/java/org/...

testNativeHistoricVariableInstanceQuery

Regards
Martin

Hello martin,
Is there any news about this issue?

gokceng1
Champ in-the-making
Champ in-the-making
I've used this code at 5.13 but hadn't faced with a problem. Don't know if this helps.
Thank you martin.

martin_grofcik
Confirmed Champ
Confirmed Champ
Thank you, and sorry - I did not have time to look at it. But basically the problem is that value retrieval is not done in the activiti command context. That's why value is not fetched from the cache and request to the DB is executed without command context. One possibility is to fetch value in the native query select command (join with ACT_GE_BYTEARRAY table). Could you try it please?
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.