Search code examples
javaeclipsedroolsclasscastexceptionaccumulate

Drools - ClassCastException in Drools 6


I have a very simple Drools project in Eclipse that runs to completion just fine, but when I open or click on my .drl file, the following error pops up in Eclipse:

An error has occurred. See error log for more details. org.drools.core.base.accumulators.BigDecimalSumAccumulateFunction cannot be cast to org.drools.runtime.rule.AccumulateFunction

When I hit OK and run the program again, it still runs fine. Whenever I click out of the .drl file and click back in, the error pops up again. The Eclipse log has the following stack trace:

!ENTRY org.eclipse.ui.workbench 4 2 2016-08-25 23:35:24.144

!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.ui.workbench".

!STACK 0 java.lang.ClassCastException: org.drools.core.base.accumulators.BigDecimalSumAccumulateFunction cannot be cast to org.drools.runtime.rule.AccumulateFunction at org.drools.compiler.PackageBuilderConfiguration.loadAccumulateFunction(PackageBuilderConfiguration.java:530) at org.drools.compiler.PackageBuilderConfiguration.buildAccumulateFunctionsMap(PackageBuilderConfiguration.java:479) at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:194) at org.drools.compiler.PackageBuilderConfiguration.(PackageBuilderConfiguration.java:170) at org.drools.eclipse.DroolsEclipsePlugin.generateParsedResource(DroolsEclipsePlugin.java:612) at org.drools.eclipse.DroolsEclipsePlugin.parseResource(DroolsEclipsePlugin.java:515) at org.drools.eclipse.editors.outline.RuleContentOutlinePage.initRules(RuleContentOutlinePage.java:279) at org.drools.eclipse.editors.outline.RuleContentOutlinePage.update(RuleContentOutlinePage.java:159) at org.drools.eclipse.editors.outline.RuleContentOutlinePage.createControl(RuleContentOutlinePage.java:133)

See the entire stack trace here: http://pastebin.com/hJK1Cs03

My program:

import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;

public class GhostFactTest {

    public static final void main(String[] args) {
        try {
            // load up the knowledge base
            KieServices ks = KieServices.Factory.get();
            KieContainer kContainer = ks.getKieClasspathContainer();
            KieSession kSession = kContainer.newKieSession("ksession-rules");

            FruitFact f1 = new FruitFact(1, "APPLE", "RED");
            FruitFact f2 = new FruitFact(2, "APPLE", "GREEN");

            kSession.insert(f1);
            kSession.insert(f2);
            kSession.fireAllRules();

            System.out.println("\n********************\nSUCCESS!\n********************");

        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
}

The .drl doesn't have to have any rules in it at all to throw the error. There are no errors at compile-time or runtime.

I have Drools 6.[0-4].0.Final installed as separate Drools runtimes, and I'm seeing this problem for every version except Drools 6.0.0.Final. I am running Java7. I am also able to run a very similar program with Drools 5.5.0.Final without any problem.

Given that the program succeeds with the expected behavior, and the error is thrown even if the .drl is empty, I'm inclined to think that this is a problem with Eclipse and my project settings. Does anyone have any guidance on how to resolve this? Thanks in advance.


Solution

  • The problem was that I was using the Drools 5.5.0.Final Eclipse plug-in with a Drools 6 project. The problem went away after I upgraded to the Drools 6.4.0.Final Eclipse plug-in.