Dear All,

We're using Drools in our project and we've been hitting a sporadic error when we insert Objects in a stateful session. Unfortunately we haven't been able to reproduce it in a constant way. We tried quite a lot of things but we haven't been able to track it to the core, but we found a way to "avoid" it, but we would love to know why this error is being triggered.

>From time to time we get the following stack trace and usually after this the rulebase gets broken (all the stateful sessions we generate with it get unusable) and we can't run anything else in it (we have to restart the app in order to create a new rule base object).

org.mvel.CompileException: cannot invoke method
    at org.mvel.optimizers.impl.refl.MethodAccessor.getValue(MethodAccessor.java:68)
    at org.mvel.optimizers.impl.refl.VariableAccessor.getValue(VariableAccessor.java:39)
    at org.mvel.ast.VariableDeepPropertyNode.getReducedValueAccelerated(VariableDeepPropertyNode.java:22)
    at org.mvel.ast.PropertyASTNode.getReducedValueAccelerated(PropertyASTNode.java:21)
    at org.mvel.MVELRuntime.execute(MVELRuntime.java:88)
    at org.mvel.CompiledExpression.getValue(CompiledExpression.java:111)
    at org.mvel.MVEL.executeExpression(MVEL.java:252)
    at org.drools.base.dataproviders.MVELDataProvider.getResults(MVELDataProvider.java:45)
    at org.drools.reteoo.FromNode.assertTuple(FromNode.java:64)
    at org.drools.reteoo.SingleTupleSinkAdapter.createAndPropagateAssertTuple(SingleTupleSinkAdapter.java:55)
    at org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:116)
    at org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:22)
    at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:140)
    at org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:318)
    at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:153)
    at org.drools.reteoo.Rete.assertObject(Rete.java:175)
    at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)
    at org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:71)
    at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:909)
    at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:881)
    at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:682)
    at uk.co.vodco.sherbet.ccp.rules.availability.AvailabilityRulesEngineImpl.addProgramme(AvailabilityRulesEngineImpl.java:27)
[removed a few lines]
Caused by: java.lang.IllegalArgumentException: java.lang.ClassCastException@1366d44
    at sun.reflect.GeneratedMethodAccessor194.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.mvel.optimizers.impl.refl.MethodAccessor.getValue(MethodAccessor.java:64)
    ... 69 common frames omitted

We found that adding a line to a few rules like the following one removed the error:

# given the version, add the programme if it does not exist
rule "insertion of programme given a version"
ruleflow-group "source-defaults"
    when
        $v: ProgrammeVersion()
        $p: Programme()
from $v.getProgramme()
        not Programme(this == $p)
    then
        insert
($p);
        update ($v); <-- Added Line
        LoggerFactory.getLogger(
"factinsertion.drl").info("Entered: insertion of programme given version");
end


Does anyone have an idea of what can be causing this error? We suppose it's related to the from clause in the condition. Because we're taking the object we're inserting in the working memory ($p) from the object $v, so in the end, for some reason, we also need to update $v.


Thanks in advance!
Augusto