]
Edson Tirelli closed JBRULES-1047.
----------------------------------
Resolution: Done
As I received no further info on this, I'm closing it. If the problem persists, please
reopen it.
class Cast Exception when using OR (||)
---------------------------------------
Key: JBRULES-1047
URL:
http://jira.jboss.com/jira/browse/JBRULES-1047
Project: JBoss Rules
Issue Type: Bug
Security Level: Public(Everyone can see)
Affects Versions: 4.0.0.GA
Environment: Windows, X86
Reporter: Arjun Dhar
Assigned To: Edson Tirelli
Priority: Trivial
Fix For: 4.0.1
When I define a rule:
When
cntct:Contact (initialized==true)
exr:Relation( contact==cntct,
active:active==$1,
relationName=="Old")
Then
contact.getStatus().setStatus(true);
contact.getStatus().addToReasonTrace(drools.getRule().getName());
end
..The bove works.
BUT, when I do the following:
When
cntct:Contact (initialized==true)
exr:Relation( contact==cntct,
active:active==$1,
relationName=="Old")
|| Relation( contact==cntct,
active:active==$1,
relationName==null)
Then
contact.getStatus().setStatus(true);
contact.getStatus().addToReasonTrace(drools.getRule().getName());
end
... The script compiles anda stateless Session is created successfully,
but at
runtime/execution it fails with the exception:
java.lang.ClassCastException: com.arjun.brms.businessObjects.Contact
org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:75)
org.drools.reteoo.EvalConditionNode.assertTuple (EvalConditionNode.java:141)
org.drools.reteoo.SingleTupleSinkAdapter.propagateAssertTuple
(SingleTupleSinkAdapter.java:20)
org.drools.reteoo.JoinNode.assertTuple(JoinNode.java:120)
org.drools.reteoo.SingleTupleSinkAdapter.propagateAssertTuple
(SingleTupleSinkAdapter.java:20)
org.drools.reteoo.JoinNode.assertObject(JoinNode.java:162)
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject
(CompositeObjectSinkAdapter.java:317)
org.drools.reteoo.AlphaNode.assertObject (AlphaNode.java:130)
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject
(CompositeObjectSinkAdapter.java:308)
org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:130)
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject
(CompositeObjectSinkAdapter.java:308)
org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:168)
org.drools.reteoo.Rete.assertObject(Rete.java:168)
org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java :190)
org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:70)
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:848)
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java :822)
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:623)
Class diagram:
~~~~~~~~~~~~~~~~
Contact<-- bi-directional association -->List<Relation>
=============================================================================
Edson comments (Response) :
-----------------------------------------
It is a bug since a more friendly message should be raised at compile time stating that
your "contact" declaration is not available in one of your logical branches.
Having said that, what you want to do is make your OR take priority over the implicit
AND and as such, you need to add () around the OR:
When
contact:Contact (initialized==true)
exr: ( Relation( contact==cntct,
active:active==$1,
relationName=="Old")
or Relation( contact==cntct,
active:active==$1,
relationName==null) )
Then
contact.getStatus().setStatus(true);
contact.getStatus().addToReasonTrace(drools.getRule().getName());
end
Having said that, better yet for you would not to use the OR CE, but to use
restriction connectives. This would be the most efficient (and clean) way of writing your
rule:
When
contact:Contact (initialized==true)
exr: Relation( contact==cntct,
active:active==$1,
relationName =="Old" || == null )
Then
contact.getStatus().setStatus(true);
contact.getStatus().addToReasonTrace(drools.getRule().getName());
end
As a syntax sugar, you could also write:
exr: Relation( contact==cntct,
active:active==$1,
relationName in ( "Old", null ) )
Can you please open a JIRA with your test case for the bug?
Thank you,
Edson
-------------------
Note: The above suggestion worked, no runtime errors with it.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: