public class MvelTest {
@Test
public void testNullDivision() {
String expression = "2 / null";
Serializable compiledExpression = MVEL.compileExpression(expression, new ParserContext());
Object value = MVEL.executeExpression(compiledExpression);
System.out.print(value); // false!
}
}
除以null在MVEL中返回false。但为什么? mvel2-2.1.3.Final
答案 0 :(得分:0)
If you actually debug this in Mvel API classes, they are explicitly returning false for this particular case.
If Mvel can fix this, it will be good. But this same issue i also encountered, so what we did, we created some intelligence before executing the expression, we modified the expression and included "IF" condition to check for the fields that are null and having operator as "/" or "*", the return null.