Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-3482

accumulate with an "and" predicate followed by an "or" causes a bogus ClassCast exception

    Details

      Description

      The following unit test exhibits a class cast exception.

      The JUnit test code, added to AccumulateTest. It crashes on the last line of the test method.

          @Test
          public void testAccumulateReverseModifyInsertLogical3() throws Exception {
              // read in the source
              final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_AccumulateReverseModifyInsertLogical3.drl" ) );
              final RuleBase ruleBase = loadRuleBase( reader );
      
              final WorkingMemory wm = ruleBase.newStatefulSession();
      
              wm.insert( new Cheese( "stilton", 10 ) );
              wm.insert( new Person( "Alice", "brie" ) );
              wm.insert( new Person( "Bob", "stilton" ) );
          }
      

      This is the rule that causes the crash:

      package org.drools.test;
      import org.drools.Cheese;
      import org.drools.Person;
      
      rule "Class cast causer"
          when
              $person      : Person( $likes : likes )
              $total       : Number() from accumulate( $p : Person(likes != $likes, $l : likes) and $c : Cheese( type == $l ),
                                                      min($c.getPrice()) )
              ($p2 : Person(name == "nobody") or $p2 : Person(name == "Doug"))
          then
              System.out.println($p2.getName());
      end  
      

      And finally this is the resulting stack trace:

      org.drools.RuntimeDroolsException: java.lang.ClassCastException: org.drools.Person cannot be cast to org.drools.Cheese
      	at org.drools.rule.Accumulate.accumulate(Accumulate.java:187)
      	at org.drools.reteoo.AccumulateNode.addMatch(AccumulateNode.java:852)
      	at org.drools.reteoo.AccumulateNode.assertObject(AccumulateNode.java:274)
      	at org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:497)
      	at org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:382)
      	at org.drools.reteoo.RightInputAdapterNode.assertLeftTuple(RightInputAdapterNode.java:142)
      	at org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:197)
      	at org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:72)
      	at org.drools.reteoo.JoinNode.assertLeftTuple(JoinNode.java:98)
      	at org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:197)
      	at org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:72)
      	at org.drools.reteoo.JoinNode.assertObject(JoinNode.java:147)
      	at org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:497)
      	at org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:382)
      	at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:235)
      	at org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:240)
      	at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:337)
      	at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:298)
      	at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:888)
      	at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:847)
      	at org.drools.integrationtests.AccumulateTest.testAccumulateReverseModifyInsertLogical3(AccumulateTest.java:622)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      	at java.lang.reflect.Method.invoke(Unknown Source)
      	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
      	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
      	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)
      Caused by: java.lang.ClassCastException: org.drools.Person cannot be cast to org.drools.Cheese
      	at org.drools.test.Rule_Class_cast_causer_5a3e8961c4834e3d9c174ff2f2d98c7bAccumulateExpression0Invoker.evaluate(Rule_Class_cast_causer_5a3e8961c4834e3d9c174ff2f2d98c7bAccumulateExpression0Invoker.java:21)
      	at org.drools.base.accumulators.JavaAccumulatorFunctionExecutor.accumulate(JavaAccumulatorFunctionExecutor.java:107)
      	at org.drools.rule.Accumulate.accumulate(Accumulate.java:178)
      	... 43 more
      

      My naive theory is that the "and" is causing an off-by-one in the compiler, and it's referencing the value assigned to $p when dereferencing $c in the min().

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  tirelli Edson Tirelli
                  Reporter:
                  chrisdolan Chris Dolan
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: