2014-02-06 22 views
0
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! 
    } 
} 

除法由MVEL分區返回false。但爲什麼? mvel2-2.1.3.FinalMVEL中由null分區返回false。這背後的邏輯是什麼?

回答

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.