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

Incremental Builds Result in ClassCastExceptions

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 5.5.1.Final
    • 5.5.0.Final
    • None
    • None

      Incremental builds via the KnowledgeAgent occasionally result in a ClassCastException, such as the following:

      java.lang.ClassCastException: org.drools.reteoo.AlphaNode$AlphaMemory cannot be cast to org.drools.reteoo.BetaMemory
      	at org.drools.reteoo.JoinNode.updateSink(JoinNode.java:398)
      	at org.drools.reteoo.RuleTerminalNode.attach(RuleTerminalNode.java:346)
      	at org.drools.reteoo.builder.ReteooRuleBuilder.addSubRule(ReteooRuleBuilder.java:174)
      	at org.drools.reteoo.builder.ReteooRuleBuilder.addRule(ReteooRuleBuilder.java:134)
      	at org.drools.reteoo.ReteooBuilder.addRule(ReteooBuilder.java:113)
      	at org.drools.reteoo.ReteooRuleBase.addRule(ReteooRuleBase.java:445)
      	at org.drools.common.AbstractRuleBase.addRule(AbstractRuleBase.java:952)
      	at org.drools.common.AbstractRuleBase.addPackages(AbstractRuleBase.java:629)
      	at org.drools.reteoo.ReteooRuleBase.addPackages(ReteooRuleBase.java:472)
      	at org.drools.impl.KnowledgeBaseImpl.addKnowledgePackages(KnowledgeBaseImpl.java:149)
      	at org.drools.agent.impl.KnowledgeAgentImpl.addResourcesToKnowledgeBase(KnowledgeAgentImpl.java:1117)
      	at org.drools.agent.impl.KnowledgeAgentImpl.incrementalBuildResources(KnowledgeAgentImpl.java:1003)
      	at org.drools.agent.impl.KnowledgeAgentImpl.buildKnowledgeBase(KnowledgeAgentImpl.java:686)
      	at org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:207)
      	at org.drools.agent.impl.KnowledgeAgentImpl$ChangeSetNotificationDetector.run_aroundBody0(KnowledgeAgentImpl.java:1301)
      	at org.drools.agent.impl.KnowledgeAgentImpl$ChangeSetNotificationDetector$AjcClosure1.run(KnowledgeAgentImpl.java:1)
      	at com.foo.DroolsBugAspect.ajc$around$com_foo_DroolsBugAspect$1$b7e32854proceed(DroolsBugAspect.aj:8)
      	at com.foo.DroolsBugAspect.ajc$around$com_foo_DroolsBugAspect$1$b7e32854(DroolsBugAspect.aj:10)
      	at org.drools.agent.impl.KnowledgeAgentImpl$ChangeSetNotificationDetector.run(KnowledgeAgentImpl.java:1295)
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
      	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
      	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
      	at java.lang.Thread.run(Thread.java:695)
      

      Steps to reproduce:

      1. Download the attached zip file (drools-bug.tar.gz)
      2. Extract the contents into a directory
      3. cd <directory>
      4. mvn install
      5. Type sh target/classes/run.sh, or else type java -classpath target/classes:target/lib/* -javaagent:target/lib/aspectjweaver-1.7.3.jar com.foo.Main
      6. Wait for a sequence of log messages similar to the following messages to begin to print to the console:
        [2013-11-06 11:05:33,742:debug] ResourceChangeScanner attempt to scan 1 resources
        [2013-11-06 11:05:33,743:debug] ResourceChangeScanner thread is waiting for 2 seconds.
        
      7. Edit target/classes/recommendations.drl in some trivial manner; for instance, I have found that editing the RHS of rule "Initialize Recommendations" by adding a print statement (e.g. System.out.println("test");) and editing the print statement a few times will reliably reproduce the problem; occasionally, merely touching the file will cause the problem to manifest.
      8. Wait for the exception to print to the console; it will look like the exception above

      Note that the exception is suppressed by the executor architecture in Drools. Thus, I had to weave an aspect that catches the exception and prints it.

      This bug also results in a memory leak, since the ResourceChangeNotifier continues to produce ChangeSet objects, but there are no consumers after the ChangeSetNotificationDetector thread terminates, resulting in an unbounded queue.

      I also noticed the following exception in development, yet was unable to reproduce it in the attached demonstration project:

      java.lang.ClassCastException: com.foo.AidAgreement cannot be cast to com.foo.Unit
      	at org.drools.base.com.foo.Unit1155259690$getAgency.getValue(Unknown Source)
      	at org.drools.base.extractors.BaseObjectClassFieldReader.getHashCode(BaseObjectClassFieldReader.java:204)
      	at org.drools.base.ClassFieldReader.getHashCode(ClassFieldReader.java:193)
      	at org.drools.core.util.AbstractHashTable$SingleIndex.hashCodeOf(AbstractHashTable.java:521)
      	at org.drools.core.util.index.RightTupleIndexHashTable.getOrCreate(RightTupleIndexHashTable.java:438)
      	at org.drools.core.util.index.RightTupleIndexHashTable.add(RightTupleIndexHashTable.java:319)
      	at org.drools.reteoo.JoinNode.assertObject(JoinNode.java:136)
      	at org.drools.reteoo.ObjectTypeNode.updateSink(ObjectTypeNode.java:334)
      	at org.drools.reteoo.BetaNode.attach(BetaNode.java:408)
      	at org.drools.reteoo.builder.BuildUtils.attachNode(BuildUtils.java:145)
      	at org.drools.reteoo.builder.GroupElementBuilder$AndBuilder.build(GroupElementBuilder.java:142)
      	at org.drools.reteoo.builder.GroupElementBuilder.build(GroupElementBuilder.java:70)
      	at org.drools.reteoo.builder.ReteooRuleBuilder.addSubRule(ReteooRuleBuilder.java:161)
      	at org.drools.reteoo.builder.ReteooRuleBuilder.addRule(ReteooRuleBuilder.java:134)
      	at org.drools.reteoo.ReteooBuilder.addRule(ReteooBuilder.java:113)
      	at org.drools.reteoo.ReteooRuleBase.addRule(ReteooRuleBase.java:445)
      	at org.drools.common.AbstractRuleBase.addRule(AbstractRuleBase.java:952)
      	at org.drools.common.AbstractRuleBase.addPackages(AbstractRuleBase.java:629)
      	at org.drools.reteoo.ReteooRuleBase.addPackages(ReteooRuleBase.java:472)
      	at org.drools.impl.KnowledgeBaseImpl.addKnowledgePackages(KnowledgeBaseImpl.java:149)
      	at org.drools.agent.impl.KnowledgeAgentImpl.addResourcesToKnowledgeBase(KnowledgeAgentImpl.java:1117)
      	at org.drools.agent.impl.KnowledgeAgentImpl.incrementalBuildResources(KnowledgeAgentImpl.java:1003)
      	at org.drools.agent.impl.KnowledgeAgentImpl.buildKnowledgeBase(KnowledgeAgentImpl.java:686)
      	at org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:207)
      	at org.drools.agent.impl.KnowledgeAgentImpl$ChangeSetNotificationDetector.run_aroundBody0(KnowledgeAgentImpl.java:1301)
      	at org.drools.agent.impl.KnowledgeAgentImpl$ChangeSetNotificationDetector$AjcClosure1.run(KnowledgeAgentImpl.java:1)
      	at com.foo.DroolsBugAspect.ajc$around$com.foo_DroolsBugAspect$1$b7e32854proceed(DroolsBugAspect.aj:8)
      	at com.foo.DroolsBugAspect.ajc$around$com.foo_DroolsBugAspect$1$b7e32854(DroolsBugAspect.aj:10)
      	at org.drools.agent.impl.KnowledgeAgentImpl$ChangeSetNotificationDetector.run(KnowledgeAgentImpl.java:1295)
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
      	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
      	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
      	at java.lang.Thread.run(Thread.java:695)
      

      The demonstration code is, of course, only intended to demonstrate the problem. It is a highly simplified and slightly sanitized version of actual code that is in development.

              mfusco@redhat.com Mario Fusco
              dtemplin_jira David Templin (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: