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

Rete tree error in Drools 5.4 (related to use of single quotes)

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

    XMLWordPrintable

Details

    • Hide

      If you run the DRL shown below, you will see that rules 2 and 3 activate and log a message. If you then comment out rule 3 in the DRL (you must put the entire rule inside /* */ characters rather than simply disabling it), and rerun it, you'll notice that rules 1 and 2 fire. How is it that the presence of rule 3 affects whether or not rule 1 activates? These two rules are not dependent in their DRL. If you look at the generated Rete trees for each example, you will notice that they differ.

      With all three rules active I get:

      [main]::INFO ::DroolsTest::test 3 hit on RecordA( id=100 ) - RecordB( id=100, role=2 )
      [main]::INFO ::DroolsTest::test 2 hit on RecordA( id=100 ) - RecordB( id=100, role=1 )

      With rule 3 commented out I get:

      [main]::INFO ::DroolsTest::test 2 hit on RecordA( id=100 ) - RecordB( id=100, role=1 )
      [main]::INFO ::DroolsTest::test 1 hit on RecordA( id=100 ) - RecordB( id=100, role=1 )

      Interestingly, if you comment out rule 2 so only rules 1 and 3 are active, rule 1 fires again:

      [main]::INFO ::DroolsTest::test 3 hit on RecordA( id=100 ) - RecordB( id=100, role=2 )
      [main]::INFO ::DroolsTest::test 1 hit on RecordA( id=100 ) - RecordB( id=100, role=1 )

      Environment: Drools 5.4.0

      package tests

      import org.apache.log4j.Logger;

      global Logger log

      declare RecordA
      id : long
      end

      declare RecordB
      id : long
      role : String
      end

      rule "insert data 1"
      salience 99999
      when
      then
      insert (new RecordA(100));
      insert (new RecordB(100, "1"));
      insert (new RecordB(100, "2"));
      end

      rule "test 1"
      when
      a : RecordA( )
      b : RecordB( id == b.id, role == '1' )
      then
      log.info(String.format("%s hit on %s - %s", kcontext.getRule().getName(), a, b));
      end

      rule "test 2"
      when
      a : RecordA( )
      b : RecordB( id == b.id, role == "1" )
      then
      log.info(String.format("%s hit on %s - %s", kcontext.getRule().getName(), a, b));
      end

      rule "test 3"
      when
      a : RecordA( )
      b : RecordB( id == b.id, role == "2" )
      then
      log.info(String.format("%s hit on %s - %s", kcontext.getRule().getName(), a, b));
      end

      Show
      If you run the DRL shown below, you will see that rules 2 and 3 activate and log a message. If you then comment out rule 3 in the DRL (you must put the entire rule inside /* */ characters rather than simply disabling it), and rerun it, you'll notice that rules 1 and 2 fire. How is it that the presence of rule 3 affects whether or not rule 1 activates? These two rules are not dependent in their DRL. If you look at the generated Rete trees for each example, you will notice that they differ. With all three rules active I get: [main] ::INFO ::DroolsTest::test 3 hit on RecordA( id=100 ) - RecordB( id=100, role=2 ) [main] ::INFO ::DroolsTest::test 2 hit on RecordA( id=100 ) - RecordB( id=100, role=1 ) With rule 3 commented out I get: [main] ::INFO ::DroolsTest::test 2 hit on RecordA( id=100 ) - RecordB( id=100, role=1 ) [main] ::INFO ::DroolsTest::test 1 hit on RecordA( id=100 ) - RecordB( id=100, role=1 ) Interestingly, if you comment out rule 2 so only rules 1 and 3 are active, rule 1 fires again: [main] ::INFO ::DroolsTest::test 3 hit on RecordA( id=100 ) - RecordB( id=100, role=2 ) [main] ::INFO ::DroolsTest::test 1 hit on RecordA( id=100 ) - RecordB( id=100, role=1 ) Environment: Drools 5.4.0 package tests import org.apache.log4j.Logger; global Logger log declare RecordA id : long end declare RecordB id : long role : String end rule "insert data 1" salience 99999 when then insert (new RecordA(100)); insert (new RecordB(100, "1")); insert (new RecordB(100, "2")); end rule "test 1" when a : RecordA( ) b : RecordB( id == b.id, role == '1' ) then log.info(String.format("%s hit on %s - %s", kcontext.getRule().getName(), a, b)); end rule "test 2" when a : RecordA( ) b : RecordB( id == b.id, role == "1" ) then log.info(String.format("%s hit on %s - %s", kcontext.getRule().getName(), a, b)); end rule "test 3" when a : RecordA( ) b : RecordB( id == b.id, role == "2" ) then log.info(String.format("%s hit on %s - %s", kcontext.getRule().getName(), a, b)); end

    Description

      Drools is not producing consistent Rete trees when a rules does an equality check with single quotes when other rules include the similar equality checks using double quotes as demonstrated in the example drl attached.

      This appears to be a problem with Drools 5.4 as the same drl works correctly in earlier Drools 5.X releases.

      Attachments

        Issue Links

          Activity

            People

              mfusco@redhat.com Mario Fusco
              bjdolbeare B Dolbeare (Inactive)
              Archiver:
              rhn-support-ceverson Clark Everson

              Dates

                Created:
                Updated:
                Resolved:
                Archived:

                PagerDuty