Uploaded image for project: 'Red Hat Decision Manager'
  1. Red Hat Decision Manager
  2. RHDM-1635

Constraints containing BigDecimal '%' operation return incorrect result after jitted.

    XMLWordPrintable

Details

    • Bug
    • Status: Verified (View Workflow)
    • Major
    • Resolution: Done
    • 7.10.0.GA
    • 7.11.0.GA
    • BRE
    • This issue was reported on RHDM 7.9.0.
      It is also reproducible on 7.10.0.

    • CR1
    • Hide

      Two reproducers are attached. reproducer_jitting_1a.zip is a reproducer similar to real-world example, and reproducer_jitting_1b.zip is a further simplified one of it.

      reproducer_jitting_1a.zip

      1. Extract reproducer.
        $ unzip reproducer_jitting_1a.zip
        $ cd reproducer_jitting_1a
        
      2. Build and execute the rule.
        $ ./run_mvn
            :
            :
        ***** start
        ***** rule_jitting_1a_4: TargetDate{date = 19500131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 19510131, leapYear = false}
        ***** rule_jitting_1a_3: TargetDate{date = 19520131, leapYear = true}
        ***** rule_jitting_1a_4: TargetDate{date = 19530131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 19540131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 19550131, leapYear = false}
        ***** rule_jitting_1a_3: TargetDate{date = 19560131, leapYear = true}
        ***** rule_jitting_1a_4: TargetDate{date = 19570131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 19580131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 19590131, leapYear = false}
        ***** rule_jitting_1a_3: TargetDate{date = 19600131, leapYear = true}
        ***** rule_jitting_1a_4: TargetDate{date = 19610131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 19620131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 19630131, leapYear = false}
        ***** rule_jitting_1a_3: TargetDate{date = 19640131, leapYear = true}
        ***** rule_jitting_1a_4: TargetDate{date = 19650131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 19660131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 19670131, leapYear = false}
        ***** rule_jitting_1a_3: TargetDate{date = 19680131, leapYear = true}
        ***** rule_jitting_1a_4: TargetDate{date = 19690131, leapYear = false}    // ..... (*4)
        ***** rule_jitting_1a_4: TargetDate{date = 19700131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 19710131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 19720131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 19730131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 19740131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 19750131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 19760131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 19770131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 19780131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 19790131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 19800131, leapYear = false}
            :
            :
        ***** rule_jitting_1a_4: TargetDate{date = 20160131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 20170131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 20180131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 20190131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 20200131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 20210131, leapYear = false}
        ***** rule_jitting_1a_4: TargetDate{date = 20220131, leapYear = false}
        ***** end
            :
            :
        

        This is a sample reproducer which determines whether the date is in a leap year. No leap year = true is seen after line (*4), which is incorrect result.

      reproducer_jitting_1b.zip

      1. Extract reproducer.
        $ unzip reproducer_jitting_1b.zip
        $ cd reproducer_jitting_1b
        
      2. Build and execute the rule.
        $ ./run_mvn
            :
            :
        ***** start
        ***** rule_jitting_1b_11: value = 10, $value = 20
        ***** rule_jitting_1b_21: value = 10, $value = 0
        ***** rule_jitting_1b_31: value = 10, $value = 100
        ***** rule_jitting_1b_41: value = 10, $value = 1
        ***** rule_jitting_1b_52: value = 10, $value = 0      // <---- rule_jitting_1b_52 is unexpectedly fired
        ***** end
            :
            :
        

        In this reproducer, -Ddrools.jittingThreshold=0 is specified in pom.xml.
        The first 4 rules fired are rules using '+', '-', '*', '/' operation respectively and they are fired as expected. The fifth rule seen is a rule using '%' operation and it is unexpectedly fired. It is correct that not rule_jitting_1b_52 but rule_jitting_1b_51 is fired.

      Show
      Two reproducers are attached. reproducer_jitting_1a.zip is a reproducer similar to real-world example, and reproducer_jitting_1b.zip is a further simplified one of it. reproducer_jitting_1a.zip Extract reproducer. $ unzip reproducer_jitting_1a.zip $ cd reproducer_jitting_1a Build and execute the rule. $ ./run_mvn : : ***** start ***** rule_jitting_1a_4: TargetDate{date = 19500131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 19510131, leapYear = false} ***** rule_jitting_1a_3: TargetDate{date = 19520131, leapYear = true} ***** rule_jitting_1a_4: TargetDate{date = 19530131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 19540131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 19550131, leapYear = false} ***** rule_jitting_1a_3: TargetDate{date = 19560131, leapYear = true} ***** rule_jitting_1a_4: TargetDate{date = 19570131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 19580131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 19590131, leapYear = false} ***** rule_jitting_1a_3: TargetDate{date = 19600131, leapYear = true} ***** rule_jitting_1a_4: TargetDate{date = 19610131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 19620131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 19630131, leapYear = false} ***** rule_jitting_1a_3: TargetDate{date = 19640131, leapYear = true} ***** rule_jitting_1a_4: TargetDate{date = 19650131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 19660131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 19670131, leapYear = false} ***** rule_jitting_1a_3: TargetDate{date = 19680131, leapYear = true} ***** rule_jitting_1a_4: TargetDate{date = 19690131, leapYear = false} // ..... (*4) ***** rule_jitting_1a_4: TargetDate{date = 19700131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 19710131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 19720131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 19730131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 19740131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 19750131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 19760131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 19770131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 19780131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 19790131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 19800131, leapYear = false} : : ***** rule_jitting_1a_4: TargetDate{date = 20160131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 20170131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 20180131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 20190131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 20200131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 20210131, leapYear = false} ***** rule_jitting_1a_4: TargetDate{date = 20220131, leapYear = false} ***** end : : This is a sample reproducer which determines whether the date is in a leap year. No leap year = true is seen after line (*4), which is incorrect result. reproducer_jitting_1b.zip Extract reproducer. $ unzip reproducer_jitting_1b.zip $ cd reproducer_jitting_1b Build and execute the rule. $ ./run_mvn : : ***** start ***** rule_jitting_1b_11: value = 10, $value = 20 ***** rule_jitting_1b_21: value = 10, $value = 0 ***** rule_jitting_1b_31: value = 10, $value = 100 ***** rule_jitting_1b_41: value = 10, $value = 1 ***** rule_jitting_1b_52: value = 10, $value = 0 // <---- rule_jitting_1b_52 is unexpectedly fired ***** end : : In this reproducer, -Ddrools.jittingThreshold=0 is specified in pom.xml . The first 4 rules fired are rules using ' + ', ' - ', ' * ', ' / ' operation respectively and they are fired as expected. The fifth rule seen is a rule using ' % ' operation and it is unexpectedly fired. It is correct that not rule_jitting_1b_52 but rule_jitting_1b_51 is fired.
    • 2021 Week 10-12 (from Mar 8)
    • +

    Description

      Once constraints containing remainder (%) operation for BigDecimal value like (*1-1) or (*1-2) are jitted, the constraints return incorrect result. The ConditionEvaluator<hash> class generated by ClassGenerator from (*1-1) is like (*2) and no remainder operation is seen in the code. (*3) is an example class generated by ClassGenerator from a constraint using '+' operator. Remainder operation for BigDecimal value should correctly jitted as well as the four basic operations '+', '-', '*', '/'.

      (*1)

      package com.example.reproducer
      
      import java.math.BigDecimal
      
      rule "rule_jitting_1b_51"
          when
              $fact : Fact( $value : (value % 10) == 0 )    // ..... (*1-1)
          then
              System.out.println("***** rule_jitting_1b_51: value = " + $fact.getValue() + ", $value = " + $value);
      end
      
      rule "rule_jitting_1b_52"
          when
              $fact : Fact( $value : (value % 10) != 0 )    // ..... (*1-2)
          then
              System.out.println("***** rule_jitting_1b_52: value = " + $fact.getValue() + ", $value = " + $value);
      end
      
      // Fact#value is a BigDecimal property.
      

      (*2) ConditionEvaluator class generated from (*1-1) in RHDM 7.10.0

      public class ConditionEvaluator87fdcd4618d94c78a57b47ccb07d9a17
      implements ConditionEvaluator {
          private static final String EXPRESSION = "(value % 10) == 0";
          private final Declaration[] declarations;
      
          public boolean evaluate(InternalFactHandle internalFactHandle, InternalWorkingMemory internalWorkingMemory, Tuple tuple) {
              BigDecimal bigDecimal = ((Fact)internalFactHandle.getObject()).getValue();
              BigDecimal bigDecimal2 = new BigDecimal("10");
              BigDecimal bigDecimal3 = new BigDecimal("0");
              return bigDecimal2 == null ? bigDecimal3 == null : (bigDecimal3 == null ? false : bigDecimal2.compareTo(bigDecimal3) == 0);
          }
      
          public ConditionEvaluator87fdcd4618d94c78a57b47ccb07d9a17(Declaration[] declarationArray) {
              this.declarations = declarationArray;
          }
      }
      

      (*3) ConditionEvaluator class generated from constraint (value + 10) == 20 in RHDM 7.10.0

      public class ConditionEvaluatorae4e42acc2d6478eb149671a9c714c32
      implements ConditionEvaluator {
          private static final String EXPRESSION = "(value + 10) == 20";
          private final Declaration[] declarations;
      
          public boolean evaluate(InternalFactHandle internalFactHandle, InternalWorkingMemory internalWorkingMemory, Tuple tuple) {
              BigDecimal bigDecimal = ((Fact)internalFactHandle.getObject()).getValue().add(new BigDecimal("10"));
              BigDecimal bigDecimal2 = new BigDecimal("20");
              return bigDecimal == null ? bigDecimal2 == null : (bigDecimal2 == null ? false : bigDecimal.compareTo(bigDecimal2) == 0);
          }
      
          public ConditionEvaluatorae4e42acc2d6478eb149671a9c714c32(Declaration[] declarationArray) {
              this.declarations = declarationArray;
          }
      }
      

      Attachments

        Activity

          People

            mfusco@redhat.com Mario Fusco
            rhn-support-myoshida Masato Yoshida
            Daniel Rosa Daniel Rosa
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: