[jboss-jira] [JBoss JIRA] (DROOLS-185) ClassCastException at ConditionEvaluator

Gurinder Randhawa (JIRA) issues at jboss.org
Sat Feb 22 19:35:47 EST 2014


    [ https://issues.jboss.org/browse/DROOLS-185?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12947085#comment-12947085 ] 

Gurinder Randhawa commented on DROOLS-185:
------------------------------------------

Davide,

Looking through our rule base we have rules such as these where casting is happening Integer -> Long, Now with the same inputs passed into working memory, the error above occurs have 10-11 requests of same type. Each request is stateless and rule session is being disposed after each request. Any insight you may provide as to how rules prepare for execution upon insertion and cause a Cast exception? Thanks.

rule "21000_SetPriceFactor_AGE"
    no-loop
    salience 7000
when
    $factorCode: RefData(code == "AGE")
    $rateGroup: RateStandardGroup()
    $rateFactorGroup: RateFactorGroup(factorType == $factorCode, parentGroupRefId == $rateGroup.refId)
    $plan: Plan(rateGroups contains $rateGroup)    
    $insuredPlan: InsuredPlan(planRefId == $plan.refId, $insuredPlan.insured.getAge() != null)    
    $factorValue : RateFactorValue() from $rateFactorGroup.matchInput(new Long($insuredPlan.insured.getAge()))
    $priceBreakdown : InsuredPlanPriceBreakdown(insuredPlan == $insuredPlan)
then
    RateFactorParameter parameter = new RateFactorParameter($factorValue, $insuredPlan.getInsured().getAge().toString());
    $priceBreakdown.createPriceComponentForParameter(parameter);
    System.out.println("21000-Set AGE Factor     |code=" + $insuredPlan.getPlanCode() + "|value="+$factorValue.getValue()+"|min="+$factorValue.getMinValue()+"|max="+$factorValue.getMaxValue()+"|age="+$insuredPlan.getInsured().getAge());
end

                
> ClassCastException at ConditionEvaluator
> ----------------------------------------
>
>                 Key: DROOLS-185
>                 URL: https://issues.jboss.org/browse/DROOLS-185
>             Project: Drools
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>    Affects Versions: 5.5.0.Final
>            Reporter: Sergey Alaev
>            Assignee: Mario Fusco
>
> Stacktrace:
> Caused by: java.lang.ClassCastException: ***** cannot be cast to ******
> 	at ConditionEvaluator443abf2927ca4f64a4ad86407ae34799.evaluate(Unknown Source)
> 	at org.drools.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:200)
> 	at org.drools.rule.constraint.MvelConstraint.isAllowed(MvelConstraint.java:157)
> 	at org.drools.reteoo.FromNode.checkConstraintsAndPropagate(FromNode.java:318)
> 	at org.drools.reteoo.FromNode.assertLeftTuple(FromNode.java:164)
> 	at org.drools.reteoo.CompositeLeftTupleSinkAdapter.doPropagateAssertLeftTuple(CompositeLeftTupleSinkAdapter.java:232)
> 	at org.drools.reteoo.CompositeLeftTupleSinkAdapter.createAndPropagateAssertLeftTuple(CompositeLeftTupleSinkAdapter.java:116)
> 	at org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:154)
> 	at org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:59)
> Reason:
> ConditionEvaluator seems to be using lazy initializing and then caches generated class to evaluate this expression with another arguments.
> Given following:
> interface A {
>    String getString();
> }
> interface B {
>    String getString();
> }
> class X implements B, A {}
> class Y implements A{}
> rule "test rule"
> when:
>      A(string != null)
> then:
> end
> When rule engine is called for the first time with instance of class X, ConditionEvaluator will bind itself to first found interface implementing method getString(), i.e. interface B.
> Thus second call with instance of class Y will cause ClassCastException of casting Y to B.
> Solution: force MVEL to bind bytecode generated methods to class/interface declared in the rule explicitly, in our case - to interface A.
> Quickfix: use following declaration of class X:
> class X implements A, B {}
> Because ConditionEvaluator binds to first available interface, it will bind now to correct interface - to interface A.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the jboss-jira mailing list