【发布时间】:2015-01-02 20:45:24
【问题描述】:
根据 [http://mvel.codehaus.org/Value+Emptiness 中的 MVEL 文档
empty
如果下面提到的条件为真,则应评估为真。
字符串的长度大于 0,但仅包含空格
一个布尔值是假的
数值为 0
但它没有给出想要的结果。
-
当字符串长度>0但仅包含空格(使用的代码如下)时,字符串案例条件评估为假。
String stringValue=" "; Map<String,Object> contextMap=new HashMap<String, Object>(); contextMap.put("stringValue", stringValue); System.out.println(MVEL.eval("stringValue == empty",contextMap)); -
对于布尔值,无论布尔值如何,它都会评估为假(使用的代码如下);
Boolean booleanValue=false; Map<String,Object> contextMap=new HashMap<String, Object>(); contextMap.put("booleanValue", booleanValue); System.out.println(MVEL.eval("booleanValue == empty",contextMap)); -
它在比较整数时显示错误。 代码:
Integer integerValue=0; Map<String,Object> contextMap=new HashMap<String, Object>(); contextMap.put("integerValue", integerValue); System.out.println(MVEL.eval("integerValue == empty",contextMap));
错误:
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
为什么它没有按照文档工作?
【问题讨论】:
-
一种被称为“虫子”的物种在软件和其他牧场上被发现。在 MVEL 错误报告网站上提交错误报告。
-
@laune 找不到任何报告错误的链接(公开)。如果有链接请分享。
-
我已经开始查询了。请稍候。
-
@laune 分享了我的分析,希望您提供一种记录错误的方法
-
@sud_shan 这是一个错误,找到一个替代方案。 :)
标签: java comparison mvel isnullorempty