cancel
Showing results for 
Search instead for 
Did you mean: 

context.getprocessengineconfiguration() is null in evaluating expression

mf
Confirmed Champ
Confirmed Champ
I have a helper method to evaluate expressions in an execution:


public Object evaluateExpression(DelegateExecution execution, String expr) {
   Expression expression = expressionManager.createExpression(expr);
   return expression.getValue(execution);
}


but in calling this method, the expression.getValue() method throws NullPointerException (only in evaluating expressions by this method):


java.lang.NullPointerException at org.activiti.engine.impl.el.JuelExpression.getValue(JuelExpression.java:45)


It shows that Context.getProcessEngineConfiguration() is null:


public Object getValue(VariableScope variableScope) {
    ELContext elContext = Context.getProcessEngineConfiguration().getExpressionManager().getElContext(variableScope);
    try {
      ExpressionGetInvocation invocation = new ExpressionGetInvocation(valueExpression, elContext);
      Context.getProcessEngineConfiguration()
        .getDelegateInterceptor()
        .handleInvocation(invocation);
      return invocation.getInvocationResult();     
    } catch (PropertyNotFoundException pnfe) {
      throw new ActivitiException("Unknown property used in expression: " + expressionText, pnfe);
    } catch (MethodNotFoundException mnfe) {
      throw new ActivitiException("Unknown method used in expression: " + expressionText, mnfe);
    } catch(ELException ele) {
      throw new ActivitiException("Error while evaluating expression: " + expressionText, ele);
    } catch (Exception e) {
      throw new ActivitiException("Error while evaluating expression: " + expressionText, e);
    }
  }


I'm not sure what is wrong! I'm using version 5.17.0.

Thanks in advance for any help you are able to provide.
4 REPLIES 4

mf
Confirmed Champ
Confirmed Champ
In addition, the expressionManager is injected with Spring. but if i use:
<java>
ExpressionManager expressionManager = Context.getProcessEngineConfiguration() .getExpressionManager();
</java>
the Context.getProcessEngineConfiguration() is null and it throws NullPointerException.

jbarrez
Star Contributor
Star Contributor
When are you executing this? The nullpointer should not happen when you call that code during an API call, and a valid CommandContext is created.

mf
Confirmed Champ
Confirmed Champ
No api call is involved and no Command Context is created; because in my use-case, i need to evaluate some expressions manually. This issue is resolved by creating a custom command:

<java>
public class EvauluateExpressionCmd implements Command<Object>, Serializable {

private static final long serialVersionUID = 1L;

private Expression expression;
private VariableScope variableScope;

public EvauluateExpressionCmd(Expression expression, VariableScope variableScope) {
  this.expression = expression;
  this.variableScope = variableScope;
}

@Override
public Object execute(CommandContext commandContext) {
  return expression.getValue(variableScope);
}
}
</java>
And execute it with ManagementService:
<java>
public Object getValue(String expr, DelegateExecution execution) {
Expression expression = expressionManager.createExpression(getEvaluableExpression(expr));
EvauluateExpressionCmd command = new EvauluateExpressionCmd(expression, execution);
return managementService.executeCommand(command);
}
</java>

But i can't figure out, when exactly we need to create custom commands??

trademak
Star Contributor
Star Contributor
When you need to run logic against an Activiti entity like the ExecutionEntity you always need a custom command, because it will need to be able to lookup Context values and be able to run a query against the Activiti entities.

Best regards,