在MVEL中除以null返回false。这背后的逻辑是什么?

时间:2014-02-06 13:20:11

标签: mvel

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

1 个答案:

答案 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.