[jboss-jira] [JBoss JIRA] (DROOLS-1386) NPE in org.drools.core.common.TupleSetsImpl.setNextTuple

Petric Coroli (JIRA) issues at jboss.org
Wed May 24 03:42:04 EDT 2017


    [ https://issues.jboss.org/browse/DROOLS-1386?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13411008#comment-13411008 ] 

Petric Coroli commented on DROOLS-1386:
---------------------------------------

[~mfusco] thanks for taking time looking into this. Even though this issue is marked as Resolved with 'can not reproduce' resolution, we do still experience the same NPE behavior. We've run same test against 7.0.0.CR3 and got similar result. 

During rule evaluation there is difference in tuples' stagedType values in between 6.3.0 and 6.5.0 (and onwards) releases for the same rule, and that affects the flow of respective TupleSets implementation _addDelete_ method

h6. In 6.3.0
{code:title=LeftTupleSetsImpl.java}
 public boolean addDelete(LeftTuple leftTuple) {
      switch(leftTuple.getStagedType()) {
      case 1:
         this.removeInsert(leftTuple);
         return this.deleteFirst == null;
      case 2:
         this.removeUpdate(leftTuple);
      default:
         leftTuple.setStagedType(3);
         if(this.deleteFirst == null) {
            this.deleteFirst = leftTuple;
            return true;
         } else {
            leftTuple.setStagedNext(this.deleteFirst);
            this.deleteFirst.setStagePrevious(leftTuple);
            this.deleteFirst = leftTuple;
            return false;
         }
      }
   }
{code}

Staged type value gives us value of 0 here for the rule in question, and thus flow takes us through the _default_ case.

h6. While In 6.5.0 and 7.0.0
{code:title=TupleSetsImpl.java}
  public boolean addDelete(T tuple) {
      switch(this.getStagedType(tuple)) {
      case 1:
         this.removeInsert(tuple);
         return this.deleteFirst == null;
      case 2:
         this.removeUpdate(tuple);
      default:
         this.setStagedType(tuple, 3);
         if(this.deleteFirst == null) {
            this.deleteFirst = tuple;
            return true;
         } else {
            this.setNextTuple(tuple, this.deleteFirst);
            this.setPreviousTuple(this.deleteFirst, tuple);
            this.deleteFirst = tuple;
            return false;
         }
      }
   }
{code}

Staged type value gives us value of _*2*_ here for the rule in question, and thus flow takes us through the 2nd case, respectively invoking _removeUpdate_ method.

Following the flow inside the _TupleSetsImpl.java.removeUpdate_, we end up in 
{code}
else {
         next = this.getNextTuple(tuple);                    // next is null 
         T previous = this.getPreviousTuple(tuple);   //  previous is null here
         if(next != null) {
            this.setPreviousTuple(next, previous);
         }
         this.setNextTuple(previous, next);  //  NPE due to previous being null
}
{code}

with _previous_ having null value, hence the NPE down the _setNextTuple_ implementation.

Main differentiator here seems to be the _stagedType_ value that was _0_ in 6.3.0 and it is _2_ now for 6.5.0 and 7.0.0, and this is taking rule evaluation through the removeUpdate method, which, presumably, should not be happening and is not expected, based on the state of the Tuple, i.e. no previous staged tuple available and this is not being asserted within removeUpdate method prior to _setNextTuple_ invocation.

Please let me know if any additional details are required, e.g. drools rule definition, stack trace etc.

This is currently a blocker for us on our way to upgrade the platform to the newer drools releases, and we would really appreciate your help on this one to get understanding whether there is something that we're missing on our end, if there are any migration steps we need to undertake from 6.3.0 to 6.5.0, or if this is a bug similar to DROOLS-1338 . Thank you in advance. 

> NPE in org.drools.core.common.TupleSetsImpl.setNextTuple
> --------------------------------------------------------
>
>                 Key: DROOLS-1386
>                 URL: https://issues.jboss.org/browse/DROOLS-1386
>             Project: Drools
>          Issue Type: Bug
>    Affects Versions: 6.5.0.Final, 7.0.0.Beta4
>            Reporter: Arkady Syamtomov
>            Assignee: Mario Fusco
>            Priority: Critical
>
> In our integration tests which were perfectly running with drools 6.3.0.Final, now we have failures with the following exception during the rules evaluation:
> java.lang.NullPointerException: null
> 	at org.drools.core.common.TupleSetsImpl.setNextTuple(TupleSetsImpl.java:349) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.common.TupleSetsImpl.removeUpdate(TupleSetsImpl.java:205) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.common.TupleSetsImpl.addDelete(TupleSetsImpl.java:110) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.reteoo.QueryElementNode$UnificationNodeViewChangedEventListener.rowRemoved(QueryElementNode.java:444) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.phreak.PhreakQueryTerminalNode.doLeftDeletes(PhreakQueryTerminalNode.java:154) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.phreak.PhreakQueryTerminalNode.doNode(PhreakQueryTerminalNode.java:46) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:282) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.phreak.RuleNetworkEvaluator.evalStackEntry(RuleNetworkEvaluator.java:198) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:141) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:94) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:194) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:73) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:970) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1312) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1251) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1364) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1355) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1346) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.command.runtime.rule.FireAllRulesCommand.execute(FireAllRulesCommand.java:109) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.command.runtime.rule.FireAllRulesCommand.execute(FireAllRulesCommand.java:36) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.command.runtime.BatchExecutionCommandImpl.execute(BatchExecutionCommandImpl.java:137) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.command.runtime.BatchExecutionCommandImpl.execute(BatchExecutionCommandImpl.java:51) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]
> 	at org.drools.core.impl.StatelessKnowledgeSessionImpl.execute(StatelessKnowledgeSessionImpl.java:254) ~[drools-core-6.5.0.Final-redhat-2.jar:6.5.0.Final-redhat-2]



--
This message was sent by Atlassian JIRA
(v7.2.3#72005)


More information about the jboss-jira mailing list