drools-正在执行规则的结果无法访问字段

soat7uwm  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(397)

有人知道什么是错的吗?当触发规则时,我得到了这个错误,但不总是这样,但是不能有任何空值。我发现了2013年的错误报告(http://drools-moved.46999.n3.nabble.com/exception-executing-consequence-for-rule--in-yyy-java-lang-runtimeexception-unable-to-access-field-td4021553.html)这似乎是同一个问题,但没有答案。
规则是:

rule "CALCULATE PARTNER ACCEPTABLE INCOME WHEN HAS PARTNER"
        agenda-group "calculation"
        when
            request:MortgageRequestDto(hasPartner == true)
        then
            response.calc.partnerAcceptableIncome = request.getPartnerIncome() * response.calc.partnerProfileMultiplier;
    end

堆栈跟踪:

2020-12-14T14:37:15.119941721Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    | org.kie.api.runtime.rule.ConsequenceException: Exception executing consequence for rule "CALCULATE PARTNER ACCEPTABLE INCOME WHEN HAS PARTNER" in defaultpkg: java.lang.RuntimeException: unable to access field
2020-12-14T14:37:15.119945181Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
2020-12-14T14:37:15.119948830Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.drools.core.common.DefaultAgenda.handleException(DefaultAgenda.java:1291)
2020-12-14T14:37:15.119951747Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:438)
2020-12-14T14:37:15.119955343Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.drools.core.phreak.RuleExecutor.fireActivation(RuleExecutor.java:380)
2020-12-14T14:37:15.119958280Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:136)
2020-12-14T14:37:15.119961292Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:89)
2020-12-14T14:37:15.119964002Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.drools.core.concurrent.AbstractRuleEvaluator.internalEvaluateAndFire(AbstractRuleEvaluator.java:33)
2020-12-14T14:37:15.120003972Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.drools.core.concurrent.SequentialRuleEvaluator.evaluateAndFire(SequentialRuleEvaluator.java:43)
2020-12-14T14:37:15.120008230Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1101)
2020-12-14T14:37:15.120011412Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.drools.core.common.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:1048)
2020-12-14T14:37:15.120014520Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1040)
2020-12-14T14:37:15.120017519Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1341)
2020-12-14T14:37:15.120020613Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1332)
2020-12-14T14:37:15.120023605Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1316)
2020-12-14T14:37:15.120026733Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at io.gbsolutions.scportal.service.MortgageRulesService.calculateMortgageOffer(MortgageRulesService.java:46)
2020-12-14T14:37:15.120030027Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at io.gbsolutions.scportal.service.MortgageOfferProviderService.provideOffer(MortgageOfferProviderService.java:28)
2020-12-14T14:37:15.120033279Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at io.gbsolutions.scportal.controller.messaging.MessagingController.calculateMortgage(MessagingController.java:55)
2020-12-14T14:37:15.120043891Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at jdk.internal.reflect.GeneratedMethodAccessor435.invoke(Unknown Source)
2020-12-14T14:37:15.120051955Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2020-12-14T14:37:15.120054960Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at java.base/java.lang.reflect.Method.invoke(Method.java:566)
2020-12-14T14:37:15.120057856Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:171)
2020-12-14T14:37:15.120061135Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:120)
2020-12-14T14:37:15.120064419Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMatch(AbstractMethodMessageHandler.java:565)
2020-12-14T14:37:15.120067710Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler.handleMatch(SimpAnnotationMethodMessageHandler.java:511)
2020-12-14T14:37:15.120070642Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler.handleMatch(SimpAnnotationMethodMessageHandler.java:94)
2020-12-14T14:37:15.120074432Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessageInternal(AbstractMethodMessageHandler.java:520)
2020-12-14T14:37:15.120077489Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessage(AbstractMethodMessageHandler.java:454)
2020-12-14T14:37:15.120080746Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.springframework.messaging.support.ExecutorSubscribableChannel$SendTask.run(ExecutorSubscribableChannel.java:144)
2020-12-14T14:37:15.120083899Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
2020-12-14T14:37:15.120087192Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
2020-12-14T14:37:15.120089817Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at java.base/java.lang.Thread.run(Thread.java:834)
2020-12-14T14:37:15.120092788Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    | Caused by: java.lang.RuntimeException: unable to access field
2020-12-14T14:37:15.120095574Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.mvel2.optimizers.impl.refl.nodes.FieldAccessor.setValue(FieldAccessor.java:63)
2020-12-14T14:37:15.120098460Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.mvel2.optimizers.impl.refl.nodes.VariableAccessor.setValue(VariableAccessor.java:46)
2020-12-14T14:37:15.120101335Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.mvel2.compiler.CompiledAccExpression.setValue(CompiledAccExpression.java:59)
2020-12-14T14:37:15.120104271Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.mvel2.ast.DeepAssignmentNode.getReducedValueAccelerated(DeepAssignmentNode.java:90)
2020-12-14T14:37:15.120107607Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
2020-12-14T14:37:15.120110709Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
2020-12-14T14:37:15.120113896Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
2020-12-14T14:37:15.120116870Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.mvel2.MVEL.executeExpression(MVEL.java:945)
2020-12-14T14:37:15.120119850Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.drools.core.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:110)
2020-12-14T14:37:15.120126303Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:431)
2020-12-14T14:37:15.120129433Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   ... 28 common frames omitted
2020-12-14T14:37:15.120133412Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    | Caused by: java.lang.RuntimeException: unable to access field
2020-12-14T14:37:15.120136689Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.mvel2.optimizers.impl.refl.nodes.FieldAccessor.setValue(FieldAccessor.java:89)
2020-12-14T14:37:15.120139641Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.mvel2.optimizers.impl.refl.nodes.FieldAccessor.setValue(FieldAccessor.java:60)
2020-12-14T14:37:15.120143066Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   ... 37 common frames omitted
2020-12-14T14:37:15.120146043Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    | Caused by: java.lang.NullPointerException: null
2020-12-14T14:37:15.120149039Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.mvel2.DataConversion.convert(DataConversion.java:129)
2020-12-14T14:37:15.120151933Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   at org.mvel2.optimizers.impl.refl.nodes.FieldAccessor.setValue(FieldAccessor.java:73)
2020-12-14T14:37:15.120154957Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |   ... 38 common frames omitted
2020-12-14T14:37:15.120157528Z gb-swarm_scportal.2.j7pbdve9cs6n@grbs0088    |
rks48beu

rks48beu1#

用mvel评估结果似乎是个问题
首先,你用的是mvel方言吗?你应该写信的 dialect "mvel" 在某个地方。
你能不能也尝试一下原始帖子中的解决方法?使用setter而不是字段访问

The workaround seems to be to replace the field assignment with a setter invocation on the field. 
i.e. 

   in lieu of 

     when 
              ... 
      then 
             $foo.x = $bar.y +$bar.z 
             ... 
      end 

do - 

     when 
              ... 
      then 
             $foo.setX($bar.y +$bar.z) 
             ... 
      end

让我们知道

相关问题