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

Rule that uses a 'collect' and 'from' clause together causes problem

    XMLWordPrintable

    Details

      Description

      Test case:

      Write a Rule that uses a 'collect' and 'from' clause together, example:

      package com.sample.mypackage

      rule "Apply discount"
      when
      $order: Order();
      $items : ArrayList() from collect (OrderItem() from $order.items)
      then
      #apply discount
      end

      first i add the package to RuleBase object, everthing works fine. When i try to 'refresh' my rules, i.e. first remove the package and again
      add the same (modified) package to the RuleBase object, following error occurs:

      java.lang.IllegalArgumentException: Cannot remove a sink, when the list of sinks is null
      at org.drools.reteoo.ObjectSource.removeObjectSink(ObjectSource.java:116)
      at org.drools.reteoo.AlphaNode.remove(AlphaNode.java:181)
      at org.drools.reteoo.LeftInputAdapterNode.remove(LeftInputAdapterNode.java:204)
      at org.drools.reteoo.FromNode.remove(FromNode.java:153)
      at org.drools.reteoo.RightInputAdapterNode.remove(RightInputAdapterNode.java:167)
      at org.drools.reteoo.BetaNode.remove(BetaNode.java:186)
      at org.drools.reteoo.RuleTerminalNode.remove(RuleTerminalNode.java:461)
      at org.drools.reteoo.ReteooBuilder.removeRule(ReteooBuilder.java:224)
      at org.drools.reteoo.ReteooRuleBase.removeRule(ReteooRuleBase.java:272)
      at org.drools.common.AbstractRuleBase.removePackage(AbstractRuleBase.java:460)
      ...

      I've found a workaround for this error by writing my .drl code as following:

      package com.sample.mypackage

      rule "Explode Cart"
      salience 11
      dialect "java"
      when
      $order: Order()
      $item : OrderItem() from $order.items
      then
      insert( $item );
      end

      rule "Apply discount"
      no-loop true
      when
      $order : Order();
      $items : ArrayList() from collect (OrderItem())
      then
      #apply discount
      end

      Now, my rules are 'refreshed' without any error.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  tirelli Edson Tirelli
                  Reporter:
                  igorb Igor Bolic
                • Votes:
                  1 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: