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

Premature rule execution

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Rejected
    • Affects Version/s: 4.0.1
    • Fix Version/s: 4.0.2
    • Component/s: None
    • Labels:
      None
    • Environment:

      JDK 1.5, Mac OS X 10.4

      Description

      Using the rules

      package test

      rule "A"

      when
      exists(x : String() and
      y : String(this!=x))

      then
      System.out.println("x!=y exists.");
      end

      rule "B"

      when
      not(exists(x : String() and
      y : String(this!=x)))

      then
      System.out.println("x!=y does not exist.");
      end

      as input for the following program (java DroolsTest <name of rule file>)

      import org.drools.*;
      import org.drools.compiler.*;
      import org.drools.rule.Package;

      import java.io.*;

      public class DroolsTest {
      private RuleBase rules;
      private StatefulSession memory;

      public DroolsTest(File file) throws Exception

      { rules =RuleBaseFactory.newRuleBase(); memory=rules.newStatefulSession(); rules.addPackage(loadPackage(file)); }

      protected Package loadPackage(File file) throws IOException {
      FileInputStream stream=null;

      try

      { stream=new FileInputStream(file); return(loadPackage(stream)); }

      finally

      { if (stream!=null) stream.close(); }

      }

      protected Package loadPackage(InputStream stream) throws IOException {
      try

      { PackageBuilder builder=new PackageBuilder(); builder.addPackageFromDrl(new InputStreamReader(stream)); return(builder.getPackage()); }

      catch(Exception ex)

      { throw new IOException(); }

      }

      public StatefulSession getSession()

      { return(memory); }

      public static void main(String ... args) {
      try

      { DroolsTest test=new DroolsTest(new File(args[0])); System.out.println("Inserting ..."); test.getSession().insert(new String("42")); test.getSession().insert(new String("42")); test.getSession().insert(new String("1701")); test.getSession().insert(new String("0815")); test.getSession().insert(new String("4711")); System.out.println("Done."); System.out.println("Firing rules ..."); test.getSession().fireAllRules(); System.out.println("Done."); }

      catch (Exception ex)

      { ex.printStackTrace(); }

      }
      }

      creates the output

      x!=y does not exist.
      Inserting ...
      Done.
      Firing rules ...
      x!=y exists.
      Done.

      Premature firing of rules seems to occur ("x!=y does not exist" before fireAllRules is invoked), which is not the expected behaviour.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                tirelli Edson Tirelli
                Reporter:
                marreitz Markus Reitz
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: