diff --git a/drools-core/src/main/java/org/drools/core/phreak/LazyPhreakBuilder.java b/drools-core/src/main/java/org/drools/core/phreak/LazyPhreakBuilder.java index 9919f985495..5b06c080f19 100644 --- a/drools-core/src/main/java/org/drools/core/phreak/LazyPhreakBuilder.java +++ b/drools-core/src/main/java/org/drools/core/phreak/LazyPhreakBuilder.java @@ -827,24 +827,23 @@ private static void processLeftTuples(LeftTupleNode node, InternalWorkingMemory AccumulateContext accctx = (AccumulateContext) lt.getContextObject(); visitChild( (LeftTuple) accctx.getResultLeftTuple(), insert, wm, rule); } - } else if (NodeTypeEnums.ExistsNode == node.getType() && - !((BetaNode)node).isRightInputIsRiaNode()) { // do not process exists with subnetworks + } else if (NodeTypeEnums.ExistsNode == node.getType() && !node.isRightInputIsRiaNode()) { // do not process exists with subnetworks // If there is a subnetwork, then there is no populated RTM, but the LTM is populated, - // so this would be procsssed in the "else". + // so this would be processed in the "else". bm = (BetaMemory) wm.getNodeMemory((MemoryFactory) node); FastIterator it = bm.getRightTupleMemory().fullFastIterator(); // done off the RightTupleMemory, as exists only have unblocked tuples on the left side - RightTuple rt = (RightTuple) BetaNode.getFirstTuple(bm.getRightTupleMemory(), it); - for (; rt != null; rt = (RightTuple) it.next(rt)) { + for (RightTuple rt = (RightTuple) BetaNode.getFirstTuple(bm.getRightTupleMemory(), it); rt != null; rt = (RightTuple) it.next(rt)) { for (LeftTuple lt = rt.getBlocked(); lt != null; lt = lt.getBlockedNext()) { - visitChild(wm, insert, rule, it, lt); + visitLeftTuple(wm, insert, rule, lt); } } } else { bm = (BetaMemory) wm.getNodeMemory((MemoryFactory) node); FastIterator it = bm.getLeftTupleMemory().fullFastIterator(); - Tuple lt = BetaNode.getFirstTuple(bm.getLeftTupleMemory(), it); - visitChild(wm, insert, rule, it, lt); + for (LeftTuple lt = (LeftTuple)BetaNode.getFirstTuple(bm.getLeftTupleMemory(), it); lt != null; lt = (LeftTuple) it.next(lt)) { + visitLeftTuple(wm, insert, rule, lt); + } } return; } else if (NodeTypeEnums.FromNode == node.getType()) { @@ -893,14 +892,12 @@ private static void processLeftTuplesOnLian( InternalWorkingMemory wm, boolean i } } - private static void visitChild(InternalWorkingMemory wm, boolean insert, Rule rule, FastIterator it, Tuple lt) { - for (; lt != null; lt = (LeftTuple) it.next(lt)) { - LeftTuple childLt = lt.getFirstChild(); - while (childLt != null) { - LeftTuple nextLt = childLt.getHandleNext(); - visitChild(childLt, insert, wm, rule); - childLt = nextLt; - } + private static void visitLeftTuple(InternalWorkingMemory wm, boolean insert, Rule rule, LeftTuple lt) { + LeftTuple childLt = lt.getFirstChild(); + while (childLt != null) { + LeftTuple nextLt = childLt.getHandleNext(); + visitChild(childLt, insert, wm, rule); + childLt = nextLt; } } diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/incrementalcompilation/IncrementalCompilationTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/incrementalcompilation/IncrementalCompilationTest.java index e20e965d41e..dbef334141b 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/incrementalcompilation/IncrementalCompilationTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/incrementalcompilation/IncrementalCompilationTest.java @@ -5165,4 +5165,62 @@ public void testReaddAllRulesWithComplexNodeSharing() { assertThat(ksession.fireAllRules()).isEqualTo(1); assertThat(fired).containsExactly("R6"); } + + @Test + public void testReaddAllRulesWithIdenticalRules() { + // DROOLS-7462 + + final String drl1 = + "import " + Message.class.getCanonicalName() + ";\n" + + "\n" + + "rule R1 when\n" + + " $m: Message()\n" + + " exists String(toString == $m.message)\n" + + "then\n" + + "end\n" + + "\n" + + "rule R2 when\n" + + " $m: Message()\n" + + " exists String(toString == $m.message)\n" + + "then\n" + + "end\n"; + + final String drl2 = + "import " + Message.class.getCanonicalName() + ";\n" + + "\n" + + "rule R3 when\n" + + " $m: Message()\n" + + " exists String(toString == $m.message)\n" + + "then\n" + + "end\n" + + "\n" + + "rule R4 when\n" + + " $m: Message()\n" + + " exists String(toString == $m.message)\n" + + "then\n" + + "end\n"; + + final KieServices ks = KieServices.Factory.get(); + + final ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0"); + KieUtil.getKieModuleFromDrls(releaseId1, kieBaseTestConfiguration, drl1); + + final KieContainer kc = ks.newKieContainer(releaseId1); + KieSession ksession = kc.newKieSession(); + + ksession.insert(new Message("test1")); + ksession.insert("test1"); + ksession.insert(new Message("test2")); + ksession.insert("test2"); + + int fired = ksession.fireAllRules(); + assertThat(fired).isEqualTo(4); + + final ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0"); + KieUtil.getKieModuleFromDrls(releaseId2, kieBaseTestConfiguration, drl2); + + kc.updateToVersion(releaseId2); + fired = ksession.fireAllRules(); + assertThat(fired).isEqualTo(4); + } }