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

NullSafeDereferencing with OR with Half binary throws NPE in exec-model

    XMLWordPrintable

Details

    • 2021 Week 25-27 (from Jun 21)
    • 2
    • NEW
    • NEW

    Description

      In exec-model, LHS like this:

        $p : Person( name == "John" || == address!.city )
      

      generates code like this:

          public boolean test(org.drools.modelcompiler.domain.Person _this) throws java.lang.Exception {
              return _this.getAddress() != null && _this.getName() == "John" || _this.getName() == _this.getAddress().getCity();
          }
      

      The code results in NPE.

      java.lang.RuntimeException: Error evaluating constraint 'name == "John" || == address!.city' in [Rule "R" in r0.drl]
      	at org.drools.model.functions.PredicateInformation.betterErrorMessage(PredicateInformation.java:56)
      	at org.drools.modelcompiler.constraints.LambdaConstraint.isAllowed(LambdaConstraint.java:178)
      	at org.drools.core.reteoo.AlphaNode.assertObject(AlphaNode.java:134)
      	at org.drools.core.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:70)
      	at org.drools.core.reteoo.ObjectTypeNode.propagateAssert(ObjectTypeNode.java:297)
      	at org.drools.core.phreak.PropagationEntry$Insert.propagate(PropagationEntry.java:162)
      	at org.drools.core.phreak.PropagationEntry$Insert.execute(PropagationEntry.java:167)
      	at org.drools.core.phreak.SynchronizedPropagationList.flush(SynchronizedPropagationList.java:100)
      	at org.drools.core.phreak.SynchronizedPropagationList.flush(SynchronizedPropagationList.java:95)
      	at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:853)
      	at org.drools.core.common.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:816)
      	at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:808)
      	at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1345)
      	at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1336)
      	at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1320)
      	at org.drools.modelcompiler.NullSafeDereferencingTest.testNullSafeDereferncingWithOr(NullSafeDereferencingTest.java:272)
      	...
      Caused by: java.lang.RuntimeException: java.lang.NullPointerException
      	at org.drools.modelcompiler.constraints.ConstraintEvaluator.evaluate(ConstraintEvaluator.java:117)
      	at org.drools.modelcompiler.constraints.LambdaConstraint.isAllowed(LambdaConstraint.java:176)
      	... 48 more
      Caused by: java.lang.NullPointerException
      	at defaultpkg.P0F.LambdaPredicate0F57A14DC065B34B61BE09A63D1FCE61.test(LambdaPredicate0F57A14DC065B34B61BE09A63D1FCE61.java:21)
      	at defaultpkg.P0F.LambdaPredicate0F57A14DC065B34B61BE09A63D1FCE61.test(LambdaPredicate0F57A14DC065B34B61BE09A63D1FCE61.java:1)
      	at org.drools.model.functions.Predicate1$Impl.test(Predicate1.java:41)
      	at org.drools.modelcompiler.constraints.ConstraintEvaluator$InnerEvaluator$_1.evaluate(ConstraintEvaluator.java:257)
      	at org.drools.modelcompiler.constraints.ConstraintEvaluator.evaluate(ConstraintEvaluator.java:115)
      	... 49 more
      

      We want to have the null check _this.getAddress() != null right before _this.getName() == _this.getAddress().getCity()

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: