tkobayas commented on PR #6364:
URL: 
https://github.com/apache/incubator-kie-drools/pull/6364#issuecomment-2934090370

   `ExecutionFlowControlTest.testInsertRetractNoloop` failed with 
   
   ```
   java.lang.NullPointerException: Cannot invoke 
"org.drools.core.util.DoubleLinkedEntry.setNext(org.drools.core.util.SingleLinkedEntry)"
 because the return value of 
"org.drools.core.util.DoubleLinkedEntry.getPrevious()" is null
   
        at org.drools.core.util.LinkedList.remove(LinkedList.java:178)
        at 
org.drools.core.phreak.RuleExecutor.removeDormantTuple(RuleExecutor.java:318)
        at 
org.drools.core.phreak.PhreakRuleTerminalNode.doLeftDelete(PhreakRuleTerminalNode.java:273)
        at 
org.drools.core.reteoo.AlphaTerminalNode.retractLeftTuple(AlphaTerminalNode.java:100)
        at 
org.drools.core.reteoo.ObjectTypeNode.lambda$retractLeftTuples$0(ObjectTypeNode.java:273)
        at 
org.drools.core.common.DefaultFactHandle$SingleLinkedTuples.forEachLeftTuple(DefaultFactHandle.java:616)
        at 
org.drools.core.common.DefaultFactHandle.forEachLeftTuple(DefaultFactHandle.java:980)
        at 
org.drools.core.reteoo.ObjectTypeNode.retractLeftTuples(ObjectTypeNode.java:272)
        at 
org.drools.core.reteoo.ObjectTypeNode.doRetractObject(ObjectTypeNode.java:250)
        at 
org.drools.core.reteoo.ObjectTypeNode.retractObject(ObjectTypeNode.java:233)
        at 
org.drools.core.reteoo.EntryPointNode.propagateRetract(EntryPointNode.java:322)
        at 
org.drools.core.phreak.PropagationEntry$Delete.execute(PropagationEntry.java:443)
        at 
org.drools.core.phreak.PropagationEntry$Delete.internalExecute(PropagationEntry.java:439)
        at 
org.drools.core.phreak.PropagationEntry.execute(PropagationEntry.java:56)
        at 
org.drools.core.phreak.SynchronizedPropagationList.flush(SynchronizedPropagationList.java:105)
        at 
org.drools.core.phreak.SynchronizedPropagationList.flush(SynchronizedPropagationList.java:95)
        at 
org.drools.kiesession.agenda.DefaultAgenda.flushPropagations(DefaultAgenda.java:868)
        at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:162)
        at 
org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:92)
        at 
org.drools.core.concurrent.AbstractGroupEvaluator.evaluateAndFire(AbstractGroupEvaluator.java:48)
        at 
org.drools.kiesession.agenda.DefaultAgenda.fireLoop(DefaultAgenda.java:620)
        at 
org.drools.kiesession.agenda.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:573)
        at 
org.drools.kiesession.agenda.DefaultAgenda.fireAllRules(DefaultAgenda.java:565)
        at 
org.drools.kiesession.session.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1093)
        at 
org.drools.kiesession.session.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1084)
        at 
org.drools.kiesession.session.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1068)
        at 
org.drools.mvel.integrationtests.ExecutionFlowControlTest.testInsertRetractNoloop(ExecutionFlowControlTest.java:804)
   ```
   
   This NPE happens with the sequence:
   
   ```
   rule "test1"
       salience 10
       no-loop true
       when
           cheese : Cheese();
       then
           delete(cheese);
           insert(cheese);
   end
   
   
   rule "test2"
       salience 0
       no-loop true
       when
           cheese : Cheese();
       then
           delete(cheese);
   end
   ```
   
   - ksession.insert(Cheese)
   - ksession.fireAllRules()
   - "test1" and "test2" matched. RuleTerminalNodeLeftTuple are created. Both 
matches are added into `activeMatches`
   - in `RuleExecutor.fire()` for "test1", `getNextTuple()` takes one match 
from `activeMatches` and moves it to `dormantMatches`
       - "test1" consequence is executed
           - delete(cheese) : PropagationEntry.Delete is put into 
propagationList
           - insert(cheese) : PropagationEntry.Insert is put into 
propagationList
       - flushPropagations()
           - Delete.execute() : retracting tuples which are associated with the 
factHandle
               -  -> RuleTerminalNodeLeftTuple(test1) -> set `Tuple.DELETE` to 
the RuleTerminalNodeLeftTuple (= This PR fix) -> 
PhreakRuleTerminalNode.doLeftDelete() -> `executor.removeDormantTuple( 
leftTuple )`. The RuleTerminalNodeLeftTuple is removed from `dormantMatches`.
               - -> RuleTerminalNodeLeftTuple(test2) -> set `Tuple.DELETE` to 
the RuleTerminalNodeLeftTuple (= This PR fix) -> 
PhreakRuleTerminalNode.doLeftDelete() -> `executor.removeActiveTuple( leftTuple 
)`. The RuleTerminalNodeLeftTuple is removed from `activeMatches`
           - Insert.propagate() : 
               - "test1" matched. RuleTerminalNodeLeftTuple is created. 
However, in `PhreakRuleTerminalNode.doLeftTupleInsert()`, it's `no-loop`, so 
it's not added to `activeMatches` nor `dormantMatches`. Orphaned tuple.
               - "test2" matched. RuleTerminalNodeLeftTuple is created. The 
match is added into `activeMatches`
   - in `RuleExecutor.fire()` for "test2", `getNextTuple()` takes one match 
from `activeMatches` and moves it to `dormantMatches`
       - "test2" consequence is executed
           - delete(cheese) : PropagationEntry.Delete is put into 
propagationList
       - flushPropagations()
           - Delete.execute() :  
               - -> RuleTerminalNodeLeftTuple(test1) -> set `Tuple.DELETE` to 
the RuleTerminalNodeLeftTuple (= This PR fix) -> 
PhreakRuleTerminalNode.doLeftDelete() -> `executor.removeDormantTuple( 
leftTuple )`. This is the orphaned tuple. Throws NPE in `removeDormantTuple`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to