嵌套对象的问题:org.drools.RuntimeDroolsException:执行谓词的异常

时间:2015-08-12 11:45:57

标签: android drools

所以我在Android上与D​​rools讨论了几个星期,当我用嵌套对象实现谓词时,我总是遇到错误。

我有以下两个类:

public final class InterventionFunction{
   private String interventionFunctionName;

   // public getter and setter
}

public class Notification{
   private InterventionFunction interventionFunction;
   private String type;

   // public getter and setter
}

我有以下规则:

rule "Education"
    when
        $n : Notification( interventionFunction.interventionFunctionName.equals("Education") )
    then
        modify ( $n ) { setType("hello") };
end

当我运行我的应用程序时,出现以下错误:

org.drools.runtime.rule.ConsequenceException: rule: Education
        at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
        at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:916)
        at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:845)
        at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1056)
        at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:733)
        at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:699)
        at org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:218)
        at com.example.jeanineharb.reasoning.DroolsTest.rules(DroolsTest.java:20)
        at ch.heiafr.pegaso.companion.TriggerSimulationActivity.sendTrigger(TriggerSimulationActivity.java:107)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at android.view.View$1.onClick(View.java:4015)
        at android.view.View.performClick(View.java:4780)
        at android.view.View$PerformClick.run(View.java:19866)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5254)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
 Caused by: org.drools.RuntimeDroolsException: Exception executing predicate interventionFunction.interventionFunctionName.equals("Education")
        at org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:298)
        at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:145)
        at org.drools.reteoo.SingleObjectSinkAdapter.propagateModifyObject(SingleObjectSinkAdapter.java:68)
        at org.drools.reteoo.ObjectTypeNode.modifyObject(ObjectTypeNode.java:266)
        at org.drools.reteoo.EntryPointNode.modifyObject(EntryPointNode.java:218)
        at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:455)
        at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:360)
        at org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:210)
        at org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:218)
        at org.drools.base.ModifyInterceptor.doAfter(ModifyInterceptor.java:59)
        at org.mvel2.ast.InterceptorWrapper.getReducedValueAccelerated(InterceptorWrapper.java:40)
        at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
        at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
        at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
        at org.mvel2.MVEL.executeExpression(MVEL.java:930)
        at org.drools.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:105)
        at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:906)
            at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:845)
            at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1056)
            at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:733)
            at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:699)
            at org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:218)
            at com.example.jeanineharb.reasoning.DroolsTest.rules(DroolsTest.java:20)
            at ch.heiafr.pegaso.companion.TriggerSimulationActivity.sendTrigger(TriggerSimulationActivity.java:107)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at android.view.View$1.onClick(View.java:4015)
            at android.view.View.performClick(View.java:4780)
            at android.view.View$PerformClick.run(View.java:19866)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
 Caused by: [Error: can't load this type of class file]
[Near : {... interventionFunction.intervent ....}]
^
[Line: 1, Column: 1]
        at org.mvel2.optimizers.impl.asm.ASMAccessorOptimizer.compileAccessor(ASMAccessorOptimizer.java:904)
        at org.mvel2.optimizers.impl.asm.ASMAccessorOptimizer.optimizeAccessor(ASMAccessorOptimizer.java:268)
        at org.mvel2.optimizers.dynamic.DynamicGetAccessor.optimize(DynamicGetAccessor.java:95)
        at org.mvel2.optimizers.dynamic.DynamicGetAccessor.getValue(DynamicGetAccessor.java:65)
        at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:108)
        at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
        at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
        at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
        at org.mvel2.MVEL.executeExpression(MVEL.java:930)
        at org.drools.base.mvel.MVELPredicateExpression.evaluate(MVELPredicateExpression.java:101)
        at org.drools.rule.PredicateConstraint.isAllowed(Predic

(在同一个规则文件中,我有另一个使用Notification类的规则,但在type属性上工作。它可以完美地工作,并且不会发出任何类型的异常。)

有谁知道这里的问题是什么?

NB:我正在使用Drools 5.2.0。

1 个答案:

答案 0 :(得分:0)

找到它。

出于某种原因,这不起作用:

rule "Education"
    when
        $n : Notification( getInterventionFunction().getInterventionFunctionName().equals("Education") )
    then
        modify ( $n ) { setType("hello") };
end

但这样做:

rule "Education"
    when
        $n : Notification( getType() == "trigger" && getInterventionFunction().getInterventionFunctionName().equals("Education") )
    then
        modify ( $n ) { setType("hello") };
end

有谁知道为什么第一个代码段拒绝工作?