cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove a variable?

iravanchi
Champ in-the-making
Champ in-the-making
Hi,

The API (ActivitiExecution class) doesn't have any method specifically for removing a variable from the execution.
I am guessing setting a variable to NULL would remove it. Am I right? If so, it would be helpful to note it in the JavaDocs (on setVariable method)

-Hamed
4 REPLIES 4

iravanchi
Champ in-the-making
Champ in-the-making
Well, apparently I was wrong. At least about non-nullable types.
When setting the variable value to null, Activiti will look at the variable type handler associated to the current value.
So, for example, if the variable is an integer, it tries to set the value of an integer to null, which throws an exception.

It depends on what is Activiti's definition for null values, but if null value means removal from the variable map, it shouldn't get to that point. (It shouldn't call VariableInstanceEntity.setValue or even VariableMap.put at all, rather remove it from the map.)

Here's the stack trace that I got, in case it can be of any help:

Caused by: java.lang.NullPointerException
at org.activiti.engine.impl.variable.IntegerType.setValue(IntegerType.java:34)
at org.activiti.engine.impl.runtime.VariableInstanceEntity.setValue(VariableInstanceEntity.java:158)
at org.activiti.engine.impl.runtime.VariableMap.put(VariableMap.java:114)
at org.activiti.engine.impl.runtime.VariableMap.put(VariableMap.java:34)
at org.activiti.pvm.impl.runtime.ExecutionImpl.setVariableLocally(ExecutionImpl.java:593)
at org.activiti.pvm.impl.runtime.ExecutionImpl.setVariable(ExecutionImpl.java:580)
at org.activiti.pvm.impl.runtime.ExecutionImpl.setVariable(ExecutionImpl.java:584)

I would create a JIRA issue, but I don't know your intended definition for null values as variable values.

jbarrez
Star Contributor
Star Contributor
Afaik, this is not possible with the current API (since null is indeed treated separately).

I added a Jira for this feature request: http://jira.codehaus.org/browse/ACT-208

shar
Champ in-the-making
Champ in-the-making
Afaik, this is not possible with the current API (since null is indeed treated separately).

I added a Jira for this feature request: http://jira.codehaus.org/browse/ACT-208
It's resolved? Any example, please.

jbarrez
Star Contributor
Star Contributor
The DelegateExecution has a method to remove the variable.