[jboss-jira] [JBoss JIRA] Resolved: (JBRULES-3224) ClassCastException when comparing class type attributes to null
Edson Tirelli (JIRA)
jira-events at lists.jboss.org
Mon Sep 26 15:03:26 EDT 2011
[ https://issues.jboss.org/browse/JBRULES-3224?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Edson Tirelli resolved JBRULES-3224.
------------------------------------
Resolution: Done
Fixed. Thanks for the bug report and solution analysis.
> ClassCastException when comparing class type attributes to null
> ---------------------------------------------------------------
>
> Key: JBRULES-3224
> URL: https://issues.jboss.org/browse/JBRULES-3224
> Project: Drools
> Issue Type: Bug
> Security Level: Public(Everyone can see)
> Components: drools-core
> Affects Versions: 5.3.0.CR1
> Reporter: Edson Tirelli
> Assignee: Edson Tirelli
> Fix For: 5.3.0.Final, 5.4.0.Beta1
>
>
> Reported by Thomas:
> ============================
> I've just tried upgrading from Drools 5.3.0-CR1 from the beta and I've hit a regression.
>
> JBoss seems to have been down for most of today so I haven't been able to raise a Jira for it.
>
> In our model we have Facts which contain fields of java.lang.class, we then have a rule which checks that they aren't null.
> Eg
> Fact { Class<Object> classField}
>
> Rule "xyz"
> When
> Fact(classField != null)
> Then
> ...
> End
>
> This is giving the following exception
>
> Caused by: java.lang.ClassCastException: org.drools.base.field.ObjectFieldImpl cannot be cast to org.drools.base.field.ClassFieldImpl
> at org.drools.base.evaluators.EqualityEvaluatorsDefinition$ClassEqualEvaluator.evaluate(EqualityEvaluatorsDefinition.java:1772)
> 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:451)
> at org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:369)
> at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:134)
> at org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:451)
> at org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:379)
> at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:204)
> 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:882)
> at org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:180)
> ... 149 more
>
> Wrapping the classField != null within an eval appears to be a work around.
>
> This is in the suspect method:
> public boolean evaluate(InternalWorkingMemory workingMemory,
> final InternalReadAccessor extractor,
> final Object object1, final FieldValue object2) {
> Object value1 = extractor.getValue( workingMemory, object1 );
> Object value2 = object2.getValue();
> if ( value2 == null ) {
> ClassFieldImpl classField = (ClassFieldImpl) object2;
> value2 = classField.resolve( workingMemory );
> }
> return comparator.equals( value1, value2 );
> }
>
> I think the if statement just needs an instanceof check as well or some other way to track the fact that null may be a valid value to be comparing with!
>
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list