commons-jexl3 issues while calling functions

Viraj Jasani <[email protected]>
Newsgroups gmane.comp.jakarta.commons.user
Message-ID <CAEY0_Yo39roqQUPTj02W908EcUc+07bOA-hR=x5nztPtUrXk5A@mail.gmail.com>
Hi,

I am using commons-jexl3 version 3.3.
Below is the sample code, where i am trying to call some functions that
return boolean.

I am running into some issues as mentioned in this email. I wonder if i am
missing something here.

------------------------------------------------------------------------------------------------------

import org.apache.commons.jexl3.JexlBuilder;
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.JexlEngine;
import org.apache.commons.jexl3.JexlExpression;
import org.apache.commons.jexl3.MapContext;

public class ComparisonExpressionUtils1 {

  public boolean isConditionExpressionMatching(final String expression) {
    JexlEngine jexlEngine = new JexlBuilder().create();
    JexlContext context = new MapContext();
    context.set("this", this);
    JexlExpression jexlExpression = jexlEngine.createExpression(expression);
    return (boolean) jexlExpression.evaluate(context);
  }

  public boolean attributeExists(final String key) {
    return false;
  }

  public boolean isEquals(final String key, final String value) {
    return false;
  }

  public static void main(String[] args) {
    ComparisonExpressionUtils1 comparisonExpressionUtils =
        new ComparisonExpressionUtils1();

System.out.println(comparisonExpressionUtils.isConditionExpressionMatching(
        "((!this.attributeExists('Id') &&
!this.attributeExists('Title_Inv')) || this.attributeExists('Author')) ||
((this.isEquals('Id', ':Id')) && ((this.isEquals('Price', ':Price')) ||
((this.isEquals('inv', ':inv')) && (this.isEquals('Title', ':Title')))))"));
  }

}

------------------------------------------------------------------------------------------------------


This is running into error:

org.apache.phoenix.expression.util.map.ComparisonExpressionUtils1.isConditionExpressionMatching:33@1:4
JEXL error : ! error caused by null operand
..
..
Caused by: org.apache.commons.jexl3.JexlArithmetic$NullOperand
at
org.apache.commons.jexl3.internal.Operators.controlNullOperands(Operators.java:104)
at
org.apache.commons.jexl3.internal.Operators.tryOverload(Operators.java:126)
at org.apache.commons.jexl3.internal.Interpreter.visit(Interpreter.java:536)
at org.apache.commons.jexl3.parser.ASTNotNode.jjtAccept(ASTNotNode.java:19)
at org.apache.commons.jexl3.internal.Interpreter.visit(Interpreter.java:843)
at org.apache.commons.jexl3.parser.ASTAndNode.jjtAccept(ASTAndNode.java:19)
at
org.apache.commons.jexl3.internal.Interpreter.visit(Interpreter.java:1109)
at
org.apache.commons.jexl3.parser.ASTReferenceExpression.jjtAccept(ASTReferenceExpression.java:36)
at org.apache.commons.jexl3.internal.Interpreter.visit(Interpreter.java:866)
at org.apache.commons.jexl3.parser.ASTOrNode.jjtAccept(ASTOrNode.java:19)
at
org.apache.commons.jexl3.internal.Interpreter.visit(Interpreter.java:1109)
at
org.apache.commons.jexl3.parser.ASTReferenceExpression.jjtAccept(ASTReferenceExpression.java:36)
at org.apache.commons.jexl3.internal.Interpreter.visit(Interpreter.java:866)
at org.apache.commons.jexl3.parser.ASTOrNode.jjtAccept(ASTOrNode.java:19)
at
org.apache.commons.jexl3.internal.Interpreter.visit(Interpreter.java:1098)
at
org.apache.commons.jexl3.parser.ASTJexlScript.jjtAccept(ASTJexlScript.java:60)
at
org.apache.commons.jexl3.internal.Interpreter.interpret(Interpreter.java:118)
at org.apache.commons.jexl3.internal.Script.execute(Script.java:197)
at org.apache.commons.jexl3.internal.Script.evaluate(Script.java:189)
... 2 more


Please let me know if I am missing something obvious.

Thanks
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.