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

Exception happens randomly in specific rule after Constraint Jitting

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 7.12.1.GA
    • 7.11.1.GA
    • BRE
    • 1
    • False
    • False
    • Release Notes
    • CR1
    • +
    • Hide

      revise the rule to be correct as Java syntax

      Show
      revise the rule to be correct as Java syntax
    • Hide

      To reproduce the exception in constraint jitting, please run attached reproducer named 'constraintJittingTest' by run_mvn.script. Please run it several times with same version of JDK and then please also run it with different version/update of jdk.

      To confirm inconsistent results of Class#getConstructors, please run attached simple project named 'bd-constructor-check' by run.sh script multiple times.

      Here are an example results.

      e.g.
      1st attempt
      =========
      ### Java Version(java.version): 11.0.7 ###

      [1] public java.math.BigDecimal(char[],int,int,java.math.MathContext)
      [2] public java.math.BigDecimal(long)
      [3] public java.math.BigDecimal(char[])
      [4] public java.math.BigDecimal(char[],java.math.MathContext)
      [5] public java.math.BigDecimal(long,java.math.MathContext)
      [6] public java.math.BigDecimal(char[],int,int)
      [7] public java.math.BigDecimal(double,java.math.MathContext)
      [8] public java.math.BigDecimal(java.math.BigInteger)
      [9] public java.math.BigDecimal(java.math.BigInteger,java.math.MathContext)
      [10] public java.math.BigDecimal(java.math.BigInteger,int)
      [11] public java.math.BigDecimal(java.math.BigInteger,int,java.math.MathContext)
      [12] public java.math.BigDecimal(int,java.math.MathContext)
      [13] public java.math.BigDecimal(int)
      [14] public java.math.BigDecimal(java.lang.String)
      [15] public java.math.BigDecimal(java.lang.String,java.math.MathContext)
      [16] public java.math.BigDecimal(double)

      2nd attempt
      =========
      ### Java version(java.version): 11.0.7 ###

      [1] public java.math.BigDecimal(char[],java.math.MathContext)
      [2] public java.math.BigDecimal(char[],int,int)
      [3] public java.math.BigDecimal(char[])
      [4] public java.math.BigDecimal(char[],int,int,java.math.MathContext)
      [5] public java.math.BigDecimal(java.math.BigInteger,int)
      [6] public java.math.BigDecimal(java.math.BigInteger,int,java.math.MathContext)
      [7] public java.math.BigDecimal(int)
      [8] public java.math.BigDecimal(int,java.math.MathContext)
      [9] public java.math.BigDecimal(long)
      [10] public java.math.BigDecimal(long,java.math.MathContext)
      [11] public java.math.BigDecimal(java.lang.String)
      [12] public java.math.BigDecimal(java.lang.String,java.math.MathContext)
      [13] public java.math.BigDecimal(double)
      [14] public java.math.BigDecimal(double,java.math.MathContext)
      [15] public java.math.BigDecimal(java.math.BigInteger)
      [16] public java.math.BigDecimal(java.math.BigInteger,java.math.MathContext)

      Show
      To reproduce the exception in constraint jitting, please run attached reproducer named 'constraintJittingTest' by run_mvn.script. Please run it several times with same version of JDK and then please also run it with different version/update of jdk. To confirm inconsistent results of Class#getConstructors , please run attached simple project named 'bd-constructor-check' by run.sh script multiple times. Here are an example results. e.g. 1st attempt ========= ### Java Version(java.version): 11.0.7 ### [1] public java.math.BigDecimal(char[],int,int,java.math.MathContext) [2] public java.math.BigDecimal(long) [3] public java.math.BigDecimal(char[]) [4] public java.math.BigDecimal(char[],java.math.MathContext) [5] public java.math.BigDecimal(long,java.math.MathContext) [6] public java.math.BigDecimal(char[],int,int) [7] public java.math.BigDecimal(double,java.math.MathContext) [8] public java.math.BigDecimal(java.math.BigInteger) [9] public java.math.BigDecimal(java.math.BigInteger,java.math.MathContext) [10] public java.math.BigDecimal(java.math.BigInteger,int) [11] public java.math.BigDecimal(java.math.BigInteger,int,java.math.MathContext) [12] public java.math.BigDecimal(int,java.math.MathContext) [13] public java.math.BigDecimal(int) [14] public java.math.BigDecimal(java.lang.String) [15] public java.math.BigDecimal(java.lang.String,java.math.MathContext) [16] public java.math.BigDecimal(double) 2nd attempt ========= ### Java version(java.version): 11.0.7 ### [1] public java.math.BigDecimal(char[],java.math.MathContext) [2] public java.math.BigDecimal(char[],int,int) [3] public java.math.BigDecimal(char[]) [4] public java.math.BigDecimal(char[],int,int,java.math.MathContext) [5] public java.math.BigDecimal(java.math.BigInteger,int) [6] public java.math.BigDecimal(java.math.BigInteger,int,java.math.MathContext) [7] public java.math.BigDecimal(int) [8] public java.math.BigDecimal(int,java.math.MathContext) [9] public java.math.BigDecimal(long) [10] public java.math.BigDecimal(long,java.math.MathContext) [11] public java.math.BigDecimal(java.lang.String) [12] public java.math.BigDecimal(java.lang.String,java.math.MathContext) [13] public java.math.BigDecimal(double) [14] public java.math.BigDecimal(double,java.math.MathContext) [15] public java.math.BigDecimal(java.math.BigInteger) [16] public java.math.BigDecimal(java.math.BigInteger,java.math.MathContext)
    • 2021 Week 49-51 (from Dec 6th), 2022 Week 02-04 (from Jan 10)

      When running the following rule multiple times,

      rule "rule1"
          when
              $f : Fact( $bd : new BigDecimal(30),
                          bd.compareTo(new BigDecimal($bd)) < 0)
          then
              System.out.println( "Rule ["+kcontext.getRule().getName()+"] is fired with fact:"+$f  );
      end
      

      sometimes exception like the following happens once Constraint Jitting takes place.

      java.lang.RuntimeException: Error evaluating constraint 'bd.compareTo($bd) < 0' in [Rule "rule2" in /home/Case/03083956/rh/constraintJittingTest/target/classes/com/sample/rules/Sample.drl]
      	at org.drools.core.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:277)
      	at org.drools.core.rule.constraint.MvelConstraint.isAllowed(MvelConstraint.java:225)
      	at org.drools.core.reteoo.AlphaNode.assertObject(AlphaNode.java:139)
      	at org.drools.core.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:503)
      	at org.drools.core.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:401)
      	at org.drools.core.reteoo.ObjectTypeNode.propagateAssert(ObjectTypeNode.java:329)
      	at org.drools.core.phreak.PropagationEntry$Insert.propagate(PropagationEntry.java:161)
      	at org.drools.core.phreak.PropagationEntry$Insert.execute(PropagationEntry.java:166)
      	at org.drools.core.phreak.SynchronizedPropagationList.flush(SynchronizedPropagationList.java:96)
      	at org.drools.core.phreak.SynchronizedPropagationList.flush(SynchronizedPropagationList.java:91)
      	at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1085)
      	at org.drools.core.common.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:1048)
      	at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1040)
      	at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1337)
      	at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1328)
      	at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1312)
      	at com.sample.DroolsTest.main(DroolsTest.java:28)
      	at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:254)
      	at java.lang.Thread.run(Thread.java:748)
      Caused by: [Error: bd.compareTo($bd): java.lang.Integer cannot be cast to java.math.BigDecimal]
      [Near : {... bd.compareTo($bd) < 0 ....}]
      

      In this example rule, $bd is BigDecimal. Therefore, new BigDecimal($bd) is incorrect as Java syntax and Constraint Jitting is trying to generate appropriate constructor by org.mvel2.util.ParseTools#getBestConstructorCandidate

      https://github.com/mvel/mvel/blob/mvel2-2.4.12.Final/src/main/java/org/mvel2/util/ParseTools.java#L496-L524

      and this results depends on Class#getConstructors.

      https://github.com/mvel/mvel/blob/mvel2-2.4.12.Final/src/main/java/org/mvel2/util/ParseTools.java#L479

      Customer reported the issue with RHDM7.7.1(mvel2-2.4.4.Final-redhat-00001) and
      org.mvel2.util.ParseTools#getBestConstructorCandidate was improved by the following commit:

      https://github.com/mvel/mvel/commit/6b8faadf042f2fc9c752148d432f2b678bdfab3e

      But the issue still happens randomly even with the latest Mvel2 version because results of Class#getConstructors are not same always. Please run attached project named 'bd-constructor-check' several times. You would see different results even when running it with same JDK version/update.

              rhn-support-tkobayas Toshiya Kobayashi
              rhn-support-hmiura Hiroko Miura
              Daniel Rosa Daniel Rosa
              Daniel Rosa Daniel Rosa
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: