Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-4560

executable-model wrongly calculates in eval with parenthesis

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • None
    • 7.27.0.Final
    • executable model

      executable-model wrongly calculates in eval with parenthesis.

      For example, with this rule,

      import org.drools.modelcompiler.domain.CalcFact;rule R when
        $p : CalcFact( $v1 : value1, $v2 : value2 )
        eval( ($v1 / ($v2 * 10) * 10) > 25 )
      then
      end
      

      if $v1 = 1 and $v2 = 1, ($v1 / ($v2 * 10) * 10) is 1. So the rule should not fire.

      However, executable-model generates Java code:

      public class Rules4A265EF484FEEE0E4E84E77B3DEB48F9RuleMethods0 {
      
          /**
           * Rule name: R
           */
          public static org.drools.model.Rule rule_R() {
              final org.drools.model.Variable<org.drools.modelcompiler.domain.CalcFact> var_$p = D.declarationOf(org.drools.modelcompiler.domain.CalcFact.class,
                                                                                                                 "$p");
              final org.drools.model.Variable<Double> var_$v1 = D.declarationOf(Double.class,
                                                                                "$v1");
              final org.drools.model.Variable<Double> var_$v2 = D.declarationOf(Double.class,
                                                                                "$v2");
              org.drools.model.Rule rule = D.rule("R").build(D.bind(var_$v1).as(var_$p,
                                                                                (_this) -> _this.getValue1()).reactOn("value1"),
                                                             D.bind(var_$v2).as(var_$p,
                                                                                (_this) -> _this.getValue2()).reactOn("value2"),
                                                             D.expr("454A1C822808AC7491268E4F381F0EDA",
                                                                    var_$v1,
                                                                    var_$v2,
                                                                    ($v1, $v2) -> org.drools.modelcompiler.util.EvaluationUtil.greaterThanNumbers($v1 / $v2 * 10 * 10,
                                                                                                                                                  25d)),
                                                             D.execute(() -> {
                                                             }));
              return rule;
          }
      }
      

      See that parentheses are removed so ($v1 / $v2 * 10 * 10) becomes 100.

              lmolteni@redhat.com Luca Molteni
              rhn-support-tkobayas Toshiya Kobayashi
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: