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

NullPointerException at ConstraintEvaluator.findPatternAndRequiredDeclaration() in accumulate with exec-model

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 7.49.0.Final
    • 7.48.0.Final
    • executable model
    • None
    • 2020 Week 52-03 (from Dec 21)
    • 4
    • Undefined
    • NEW
    • NEW
    • ---
    • ---

      With exec-model, a rule like this:

      when
          Number(  ) from accumulate (
            FactA( $valueA : value )
            and
            FactB( $valueB : value, eval($valueB.compareTo($valueA) <= 0) )
            ;max($valueB.intValue())
          )
      then
      

      generates the following PATTERN_DSL:

              org.drools.model.Rule rule = D.rule("org.drools.mvel.compiler",
                                                  "r1").build(D.pattern(var_GENERATED_$pattern_Number$1$),
                                                              D.accumulate(D.and(D.pattern(var_GENERATED_$pattern_FactA$2$).bind(var_$valueA,
                                                                                                                                 org.drools.mvel.compiler.P46.LambdaExtractor468EFEB3BE9EA6494C88709DE97051CB.INSTANCE,
                                                                                                                                 D.reactOn("value")),
                                                                                 D.pattern(var_GENERATED_$pattern_FactB$3$).bind(var_6C0A578A2EA3D5A5C82ABB0FA0DE5C71,
                                                                                                                                 org.drools.mvel.compiler.P18.LambdaExtractor18D900ABC004631DF004CDA316CD34FD.INSTANCE,
                                                                                                                                 D.reactOn("value")).expr("A574527869CA97E0B100815026E8E8FA",
                                                                                                                                                          var_$valueB,
                                                                                                                                                          var_$valueA,
                                                                                                                                                          org.drools.mvel.compiler.P3E.LambdaPredicate3E396A3A5FB9CCA4FC041866C27E4A3A.INSTANCE)),
                                                                           D.accFunction(org.drools.core.base.accumulators.IntegerMaxAccumulateFunction::new,
                                                                                         var_6C0A578A2EA3D5A5C82ABB0FA0DE5C71).as(var_GENERATED_$pattern_Number$1$)),
                                                              D.execute(org.drools.mvel.compiler.P97.LambdaConsequence97C360F7B2C85569E6224ABDE862C784.INSTANCE));
      

      It misses bind() for var_$valueB. It results in NPE during kbase build.

      java.lang.NullPointerException
      	at org.drools.modelcompiler.constraints.ConstraintEvaluator.findPatternAndRequiredDeclaration(ConstraintEvaluator.java:97)
      	at org.drools.modelcompiler.constraints.ConstraintEvaluator.<init>(ConstraintEvaluator.java:67)
      	at org.drools.modelcompiler.KiePackagesBuilder.createSingleConstraint(KiePackagesBuilder.java:1064)
      	at org.drools.modelcompiler.KiePackagesBuilder.createConstraint(KiePackagesBuilder.java:1049)
      	at org.drools.modelcompiler.KiePackagesBuilder.addConstraintsToPattern(KiePackagesBuilder.java:1043)
      	at org.drools.modelcompiler.KiePackagesBuilder.buildPattern(KiePackagesBuilder.java:730)
      	at org.drools.modelcompiler.KiePackagesBuilder.recursivelyAddConditions(KiePackagesBuilder.java:624)
      	at org.drools.modelcompiler.KiePackagesBuilder.buildAccumulate(KiePackagesBuilder.java:581)
      	at org.drools.modelcompiler.KiePackagesBuilder.conditionToElement(KiePackagesBuilder.java:493)
      	at org.drools.modelcompiler.KiePackagesBuilder.addSubConditions(KiePackagesBuilder.java:655)
      	at org.drools.modelcompiler.KiePackagesBuilder.populateLHS(KiePackagesBuilder.java:449)
      	at org.drools.modelcompiler.KiePackagesBuilder.compileRule(KiePackagesBuilder.java:249)
      	at org.drools.modelcompiler.KiePackagesBuilder.build(KiePackagesBuilder.java:220)
      	at org.drools.modelcompiler.CanonicalKieModule.createKiePackages(CanonicalKieModule.java:306)
      	at org.drools.modelcompiler.CanonicalKieModule.lambda$1(CanonicalKieModule.java:213)
      	at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
      	at org.drools.modelcompiler.CanonicalKieModule.createKieBase(CanonicalKieModule.java:213)
      	at org.drools.compiler.kie.builder.impl.KieContainerImpl.createKieBase(KieContainerImpl.java:470)
      

      ====
      Even this rule causes the issue. So the key factor is the method invocation $valueB.intValue()

      when
          Number(  ) from accumulate (
            FactB( $valueB : value, $valueB > 0 )
            ;max($valueB.intValue())
          )
      then
      

              rhn-support-tkobayas Toshiya Kobayashi
              rhn-support-tkobayas Toshiya Kobayashi
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: