Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-1047

class Cast Exception when using OR (||)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Trivial
    • Resolution: Done
    • Affects Version/s: 4.0.0.GA
    • Fix Version/s: 4.0.1
    • Component/s: None
    • Labels:
      None
    • Environment:

      Windows, X86

      Description

      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.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                tirelli Edson Tirelli
                Reporter:
                ArjunDhar Arjun Dhar
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: