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

Wrong condition evaluation if the condition contains a variable assignment

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

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • 6.0.0.Alpha1
    • 5.0.1.FINAL
    • drools-core
    • None

    Description

      I have a rule which checks variables of two equal objects in an old and a new version. If I work with the variable daclaration $nd1 then the consequence is NOT executed although it should.

      This is the version of the rule in that the consequence is not executed although it should:

      ------------------------------------------

      package apm.event.resource;

      #list any import classes here.
      import java.util.*;
      import de.fraport.test.*;

      #declare any global variables here
      global Collection results;

      rule "Test-Del"
      salience 900
      when
      #conditions
      TestMainObjectPair( $omo: oldMainObject != null, $nmo: newMainObject )
      TestObject( date1 == null, $od2: date2 != null, $os1: strVal1 != null ) from $omo.testObject
      TestObject( $nd1: date1 != null || date2 != $od2 || strVal1 != $os1 ) from $nmo.testObject

      then
      #actions
      System.out.println("****** Executing consequence of rule Test-Del nd1="+ $nd1 +" ...");
      results.add($nto);
      end

      ------------------------------------------

      This is the rule version which delivers the expected result (without using $nd1):

      ------------------------------------------

      package apm.event.resource;

      #list any import classes here.
      import java.util.*;
      import de.fraport.test.*;

      #declare any global variables here
      global Collection results;

      rule "Test-Del"
      salience 900
      when
      #conditions
      TestMainObjectPair( $omo: oldMainObject != null, $nmo: newMainObject )
      TestObject( date1 == null, $od2: date2 != null, $os1: strVal1 != null ) from $omo.testObject
      $nto: TestObject( date1 != null || date2 != $od2 || strVal1 != $os1 ) from $nmo.testObject

      then
      #actions
      System.out.println("****** Executing consequence of rule Test-Del nd1="+ $nto.getDate1() +" ...");
      results.add($nto);
      end

      ------------------------------------------

      If wished, I have a corresponding JUnit test case for this issue.

      Attachments

        Activity

          People

            etirelli@redhat.com Edson Tirelli
            ukkm_jira Udo Klinkmüller (Inactive)
            Archiver:
            rhn-support-ceverson Clark Everson

            Dates

              Created:
              Updated:
              Archived:

              PagerDuty