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

NPE on org.kie.api.runtime.rule.FactHandle.getObject() with DRL contain NOT operator

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Critical Critical
    • None
    • 8.44.0.Final
    • core engine
    • None
    • NEW
    • NEW
    • ---
    • ---

      This is the sample DRL content:

      package com.sample;
      
      import java.util.Map;
      import java.math.BigDecimal;
      import com.sample.Cart;
      import com.sample.Product;
      import com.sample.Context;
      
      import com.sample.CartDiscountAction;
      
      query accumulate_query(Cart $v1, Product $v2)
         (
            not (
               $v2 := Product(leftQuantity >= Integer.valueOf(1))
               and
               $v1 := Cart(products contains $v2)
               and
               (
                  $v2 := Product(code == "20000" || categoryCodes contains "20000")
               )
            )
            and
            (
               $v2 := Product(price >= new BigDecimal("300"), leftQuantity >= Integer.valueOf(1))
               and
               $v1 := Cart(products contains $v2)
            )
         )
      end
      
      rule "testProductAction"
      
      dialect "mvel"
      no-loop false
      salience 0
      when
            (
            not (
               $rao_v2 := Product(leftQuantity >= Integer.valueOf(1))
               and
               exists (Cart(products contains $rao_v2))
               and
               (
                  $rao_v2 := Product(code == "20000" || categoryCodes contains "20000")
               )
            )
            and
            (
               $rao_v2 := Product(price >= new BigDecimal("300"), leftQuantity >= Integer.valueOf(1))
               and
               exists (Cart(products contains $rao_v2))
            )
         )
         $v1 := Cart()
         accumulate (
            accumulate_query($v1, $v2;)
         ;
            $v1_set : collectSet($v1),
            $v2_set : collectSet($v2),
            $result_count : count(1)
         )
         $action := CartDiscountAction()
         eval($result_count > 0)
      then
         Map variables = [
            "com.sample.Cart" : $v1_set,
            "com.sample.Product": $v2_set
         ];
         $action.execution(new Context(variables, kcontext));
      end
       

      To reproduce this issue, please open the attachment file. It is a maven project.

      This project contains the above DLR file, and include the drools version 8.44.0.Final.

      To run command `mvn clean test` to execute the unit test, then the NullPointerException will be thrown.

      Here is the calltrace:

      java.lang.NullPointerException: Cannot invoke "org.kie.api.runtime.rule.FactHandle.getObject()" because "fh" is null
          at org.drools.base.rule.Declaration.getValue(Declaration.java:231)
          at org.drools.base.rule.Declaration.getValue(Declaration.java:227)
          at org.drools.base.rule.accessor.TupleValueExtractor.getValue(TupleValueExtractor.java:26)
          at org.drools.base.util.FieldIndex.indexedValueOf(FieldIndex.java:79)
          at org.drools.core.util.AbstractHashTable$SingleIndex.hashCodeOf(AbstractHashTable.java:234)
          at org.drools.core.util.index.TupleIndexHashTable.getOrCreate(TupleIndexHashTable.java:395)
          at org.drools.core.util.index.TupleIndexHashTable.add(TupleIndexHashTable.java:357)
          at org.drools.core.phreak.PhreakJoinNode.doLeftInserts(PhreakJoinNode.java:95)
          at org.drools.core.phreak.PhreakJoinNode.doNode(PhreakJoinNode.java:71)
          at org.drools.core.phreak.RuleNetworkEvaluator.switchOnDoBetaNode(RuleNetworkEvaluator.java:576)
          at org.drools.core.phreak.RuleNetworkEvaluator.evalBetaNode(RuleNetworkEvaluator.java:562)
          at org.drools.core.phreak.RuleNetworkEvaluator.evalNode(RuleNetworkEvaluator.java:389)
          at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:349)
          at org.drools.core.phreak.RuleNetworkEvaluator.doRiaNode(RuleNetworkEvaluator.java:634)
          at org.drools.core.phreak.RuleNetworkEvaluator.evalBetaNode(RuleNetworkEvaluator.java:557)
          at org.drools.core.phreak.RuleNetworkEvaluator.evalNode(RuleNetworkEvaluator.java:389)
          at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:349)
          at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:185)
          at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:143)
          at org.drools.core.phreak.RuleExecutor.evaluateNetwork(RuleExecutor.java:221)
          at org.drools.kiesession.agenda.DefaultAgenda.evaluateEagerList(DefaultAgenda.java:501)
          at org.drools.kiesession.agenda.DefaultAgenda.fireLoop(DefaultAgenda.java:618)
          at org.drools.kiesession.agenda.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:571)
          at org.drools.kiesession.agenda.DefaultAgenda.fireAllRules(DefaultAgenda.java:563)
          at org.drools.kiesession.session.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1088)
          at org.drools.kiesession.session.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1079)
          at org.drools.kiesession.session.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1063)
          at com.sample.NotOperationTest.testProductExist(NotOperationTest.java:59)
          at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
      ...... 

       

      This DRL file could be executed successfully in Drools version 7.74.1.Final.

              mfusco@redhat.com Mario Fusco
              eric.zeng02@sap.com Eric Zeng (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: