But isn't the java.lang.runtimeException thrown up to the point where you
call fireAllrules() in your RulesEngine.java at line 318? Just catching NPE
is a little dodgy since you can't know what might happen.
-W
On 28 March 2012 18:35, scottleff <scott.leff(a)fbfs.com> wrote:
During development of our Drools rule base I had a case where a rule
compiled
fine, but at runtime a NPE is thrown by MVEL when applying the predicate
(LHS) because the Coverage.vehicleSupplement attribute was NULL. I had
expected the NPE to be returned to my calling java program so that my
try/catch could address the issue. However, the exception was sent to
System.err and the rule was simply skipped. First, is the the default
behavior in Drools for Exceptions thrown from the LHS? If so, can it be
overridden to actually return the exception?
rule "BR--UM Stacked Coverage"
agenda-group "BR_Change"
dialect "mvel"
when
coverage : Coverage( vehicleSupplement.stackable == true ,
coverageCode ==
"UDCSL")
vehicle : Vehicle( unitAtRiskNumber : unitAtRiskNumber)
Policy( state == "NM" )
then
WorkItemReason fact0 = new WorkItemReason();
fact0.setType( "Policy" );
fact0.setReason( "6408: UM/UDM stacking change" );
fact0.setAddBookmark( "VE" );
fact0.setAddBookmarkUnit( unitAtRiskNumber );
insertLogical(fact0 );
end
*Here is the stacktrace from my console:*
WARNING: java.lang.RuntimeException: cannot invoke getter:
getVehicleSupplement [declr.class: com.fbfs.pc.ecd.model.Coverage;
act.class: com.fbfs.pc.ecd.model.Coverage] (see trace)
at
org.mvel2.optimizers.impl.refl.nodes.GetterAccessor.getValue(GetterAccessor.java:74)
at
org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:106)
at org.mvel2.MVELRuntime.execute(MVELRuntime.java:87)
at
org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:122)
at org.mvel2.MVEL.executeExpression(MVEL.java:954)
at
org.drools.base.extractors.MVELClassFieldReader.getValue(MVELClassFieldReader.java:100)
at
org.drools.base.extractors.BaseObjectClassFieldReader.isNullValue(BaseObjectClassFieldReader.java:179)
at
org.drools.base.evaluators.EqualityEvaluatorsDefinition$BooleanEqualEvaluator.evaluate(EqualityEvaluatorsDefinition.java:555)
at
org.drools.rule.LiteralRestriction.isAllowed(LiteralRestriction.java:87)
at
org.drools.rule.LiteralConstraint.isAllowed(LiteralConstraint.java:109)
at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:130)
at
org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:458)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:386)
at
org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:215)
at
org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:244)
at
org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:330)
at
org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:291)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:886)
at
org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:180)
at
org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:174)
at
PolicyDefinitionRules.Rule_policyDefinition_UnitAtRiskCoverage.defaultConsequence(Rule_policyDefinition_UnitAtRiskCoverage.java:8)
at
PolicyDefinitionRules.Rule_policyDefinition_UnitAtRiskCoverageDefaultConsequenceInvoker.evaluate(Unknown
Source)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1091)
at
org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1029)
at
org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1251)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:708)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:672)
at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:218)
at
com.fbfs.pc.rulesengine.controller.RulesEngine.runRulesEngine(RulesEngine.java:318)
My expectation that Exceptions thrown from the consequence (RHS) are
returned to the calling program was confirmed when I added the following 2
lines to a rule that was not experiencing the above issue:
String myString = null;
System.out.println(myString.trim());
Is there any good documentation on Drools exception handling?
Current configuration is Drools 5.3.0, MVEL 2.1.0, Glassfish 2.1
--
View this message in context:
http://drools.46999.n3.nabble.com/NPE-from-LHS-of-rule-is-not-returned-by...
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users