As per the documentation for MVEL in [http://mvel.codehaus.org/Value+Emptiness
empty
should evaluate to true if the below mentioned conditions are true.
a string has a length greater than 0 but is comprised only of whitespace
a boolean value is false
a numeric value is 0
But It does not give desired result.
For String case condition evaluates to false when String length>0 but comprised only of whitespace(Code used is given below).
String stringValue=" "; Map<String,Object> contextMap=new HashMap<String, Object>(); contextMap.put("stringValue", stringValue); System.out.println(MVEL.eval("stringValue == empty",contextMap));
For Boolean it evalautes to false irrespective of boolean value(Code used is given below);
Boolean booleanValue=false; Map<String,Object> contextMap=new HashMap<String, Object>(); contextMap.put("booleanValue", booleanValue); System.out.println(MVEL.eval("booleanValue == empty",contextMap));
And it shows error on comparing integers. Code:
Integer integerValue=0; Map<String,Object> contextMap=new HashMap<String, Object>(); contextMap.put("integerValue", integerValue); System.out.println(MVEL.eval("integerValue == empty",contextMap));
Error:
Exception in thread "main" [Error: failed to subEval expression]
[Near : {... integerValue == empty ....}]
^
[Line: 1, Column: 17]
at org.mvel2.compiler.AbstractParser.reduce(AbstractParser.java:2653)
at org.mvel2.compiler.AbstractParser.arithmeticFunctionReduction(AbstractParser.java:2552)
at org.mvel2.MVELInterpretedRuntime.parseAndExecuteInterpreted(MVELInterpretedRuntime.java:152)
at org.mvel2.MVELInterpretedRuntime.parse(MVELInterpretedRuntime.java:49)
at org.mvel2.MVEL.eval(MVEL.java:165)
at com.Test1.main(Test1.java:15)
Caused by: java.lang.RuntimeException: cannot convert <> to a numeric type: class org.mvel2.compiler.BlankLiteral [200]
at org.mvel2.math.MathProcessor.getNumber(MathProcessor.java:702)
at org.mvel2.math.MathProcessor._doOperations(MathProcessor.java:214)
at org.mvel2.math.MathProcessor.doOperations(MathProcessor.java:79)
at org.mvel2.math.MathProcessor.doOperations(MathProcessor.java:48)
at org.mvel2.util.ExecutionStack.op(ExecutionStack.java:178)
at org.mvel2.compiler.AbstractParser.reduce(AbstractParser.java:2593)
... 5 more
Why it is not working as per documentation?