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

In a catch22 using a NOT constraint in rules shared by multiple facts

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 6.3.0.Beta2
    • 6.0.1.Final, 6.1.0.Final
    • core engine
    • None

      I have a reproducer for these related issues.

      We have encountered a couple of issues (Exceptions) when using a NOT constraint in rules that have facts associated with them when we call upgradeToVersion() or kSession.delete(). The catch22 is that one version of the NOT constraint avoids one Exception while causing another. Reproducing the issue requires 2 rules sharing the same NOT constraint. I have narrowed the issue(s) down to 2 very simple rules that use the org.drools.compiler.FactA class.

      Here are the 2 rules used:

      static final String ruleDrl = "package org.some.test\n" +
      "import org.drools.compiler.FactA\n" +
      "declare FactA\n" +
      "@role(event)" +
      "end\n" +
      "rule \"R200_0\" when\n" +
      " $FactA : FactA ($FactA_field2 : field2 == 111002)\n" +
      " not FactA($FactA_field2 == 111002, this after $FactA)\n" + // version A: using this version causes a NPE when calling ksession.delete()
      // " not FactA(field2 == 111002, this after $FactA)\n" + // Version B: using this version causes the IllegalArgumentException: Cannot remove a sink,
      // when the list of sinks is null on the updateToVersion() call

      "then\n" +
      "end\n";

      static final String ruleDrl2 = "package org.some.test\n" +
      "import org.drools.compiler.FactA\n" +
      "declare FactA\n" +
      "@role(event)" +
      "end\n" +
      "rule \"R1437_0\" when\n" +
      " $FactA : FactA ($FactA_field2 : field2 == 105742)\n" +
      " not FactA($FactA_field2 == 105742, this after $FactA)\n" + // version A:
      // " not FactA(field2 == 105742, this after $FactA)\n" + // Version B:
      "then\n" +
      "end\n";

      We are hitting the following NPE using the reproducer code attached when we use the NOT Constraint labeled as 'Version A' in the rule:

      java.lang.NullPointerExceptionNullPointerException caught: 2

      at org.drools.core.reteoo.NotNode.doDeleteRightTuple(NotNode.java:186)
      at org.drools.core.reteoo.NotNode.retractRightTuple(NotNode.java:174)
      at org.drools.core.reteoo.ObjectTypeNode.doRetractObject(ObjectTypeNode.java:345)
      at org.drools.core.reteoo.ObjectTypeNode.retractObject(ObjectTypeNode.java:337)
      at org.drools.core.reteoo.EntryPointNode.retractObject(EntryPointNode.java:379)
      at org.drools.core.common.NamedEntryPoint.delete(NamedEntryPoint.java:612)
      at org.drools.core.impl.StatefulKnowledgeSessionImpl.delete(StatefulKnowledgeSessionImpl.java:1467)
      at org.drools.core.impl.StatefulKnowledgeSessionImpl.delete(StatefulKnowledgeSessionImpl.java:1458)
      at org.drools.compiler.integrationTests.RemovingARuleCausesNPE.test(RemovingARuleCausesNPE.java:187)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
      at java.lang.reflect.Method.invoke(Method.java:611)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
      at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

      We are hitting the following IllegalArgumentException using the reproducer code attached when we use the NOT Constraint labeled as 'Version B' in the rule:

      java.lang.IllegalArgumentException: Cannot remove a sink, when the list of sinks is null
      at org.drools.core.reteoo.ObjectSource.removeObjectSink(ObjectSource.java:203)
      at org.drools.core.reteoo.ObjectSource.doRemove(ObjectSource.java:242)
      at org.drools.core.common.BaseNode.remove(BaseNode.java:122)
      at org.drools.core.reteoo.ReteooBuilder.removeNode(ReteooBuilder.java:236)
      at org.drools.core.reteoo.ReteooBuilder.removeTerminalNode(ReteooBuilder.java:179)
      at org.drools.core.reteoo.ReteooBuilder.removeRule(ReteooBuilder.java:153)
      at org.drools.core.impl.KnowledgeBaseImpl.removeRule(KnowledgeBaseImpl.java:1535)
      at org.drools.core.impl.KnowledgeBaseImpl.removeObjectsGeneratedFromResource(KnowledgeBaseImpl.java:1768)
      at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.removeObjectsGeneratedFromResource(KnowledgeBuilderImpl.java:2029)
      at org.drools.compiler.kie.builder.impl.KieContainerImpl.update(KieContainerImpl.java:171)
      at org.drools.compiler.kie.builder.impl.KieContainerImpl.updateToVersion(KieContainerImpl.java:104)
      at org.drools.compiler.integrationTests.RemovingARuleCausesNPE.test(RemovingARuleCausesNPE.java:172)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
      at java.lang.reflect.Method.invoke(Method.java:611)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
      at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

              mfusco@redhat.com Mario Fusco
              billt408_jira Bill Tuminaro (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: