The result of BigDecimal-type binary operation when either one or both operands are null becomes a String-type or Boolean-type value.
For example, when the expressions in RHS of a rule is like (*1) below, the results will be a String-type value or a Boolean-type value `false`.
(*1) Example rule
dialect "mvel" rule "rule1a" when Calc( $a : a, $b : b ) then System.out.print("***** Action of rule1a: " + $a + " + " + $b); BigDecimal $c = $a + $b; .......... (*1-1) System.out.println(" = " + $c + " (" + $c.getClass().getName() + ")"); System.out.print("***** Action of rule1a: " + $a + " - " + $b); BigDecimal $c = $a - $b; .......... (*1-2) System.out.println(" = " + $c + " (" + $c.getClass().getName() + ")"); System.out.print("***** Action of rule1a: " + $a + " * " + $b); BigDecimal $c = $a * $b; .......... (*1-3) System.out.println(" = " + $c + " (" + $c.getClass().getName() + ")"); System.out.print("***** Action of rule1a: " + $a + " / " + $b); BigDecimal $c = $a / $b; .......... (*1-4) System.out.println(" = " + $c + " (" + $c.getClass().getName() + ")"); System.out.print("***** Action of rule1a: " + $a + " % " + $b); BigDecimal $c = $a % $b; .......... (*1-5) System.out.println(" = " + $c + " (" + $c.getClass().getName() + ")"); end // a and b of Calc are BigDecimal-type properties.
(*2) Java code inserting and calling fireAllRules
Calc calc1 = new Calc(new BigDecimal("0"), new BigDecimal("1")); kSession.insert(calc1); Calc calc2 = new Calc(new BigDecimal("0"), null); kSession.insert(calc2); Calc calc3 = new Calc(null, new BigDecimal("0")); kSession.insert(calc3); Calc calc4 = new Calc(null, null); kSession.insert(calc4); System.out.println("***** start"); kSession.fireAllRules(); System.out.println("***** end");
(*3) Output (each parenthesis shows the result type of the operation)
***** start ***** Action of rule1a: 0 + 1 = 1 (java.math.BigDecimal) ***** Action of rule1a: 0 - 1 = -1 (java.math.BigDecimal) ***** Action of rule1a: 0 * 1 = 0 (java.math.BigDecimal) ***** Action of rule1a: 0 / 1 = 0 (java.math.BigDecimal) ***** Action of rule1a: 0 % 1 = 0 (java.math.BigDecimal) ***** Action of rule1a: 0 + null = 0null (java.lang.String) ***** Action of rule1a: 0 - null = false (java.lang.Boolean) ***** Action of rule1a: 0 * null = false (java.lang.Boolean) ***** Action of rule1a: 0 / null = false (java.lang.Boolean) ***** Action of rule1a: 0 % null = false (java.lang.Boolean) ***** Action of rule1a: null + 0 = null0 (java.lang.String) ***** Action of rule1a: null - 0 = false (java.lang.Boolean) ***** Action of rule1a: null * 0 = false (java.lang.Boolean) ***** Action of rule1a: null / 0 = false (java.lang.Boolean) ***** Action of rule1a: null % 0 = false (java.lang.Boolean) ***** Action of rule1a: null + null = nullnull (java.lang.String) ***** Action of rule1a: null - null = false (java.lang.Boolean) ***** Action of rule1a: null * null = false (java.lang.Boolean) ***** Action of rule1a: null / null = false (java.lang.Boolean) ***** Action of rule1a: null % null = false (java.lang.Boolean) ***** end
This issue can be seen when we are not using the executable model but plain drl.
It is not appropriate the result of these operations are a String or Boolean-type value.
- incorporates
-
DROOLS-6741 Upgrade to mvel 2.4.14+
- Closed