Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-4909

Infinite recursion in drools after version change from v7.20 to v7.21

    XMLWordPrintable

Details

    • Bug
    • Resolution: Not a Bug
    • Major
    • None
    • 7.21.0.Final, 7.22.0.Final, 7.23.0.Final, 7.25.0.Final, 7.31.0.Final
    • core engine
    • None
    • 2020 Week 01-03 (from Dec 30)
    • Hide

      Steps to Reproduce are in the description

      Show
      Steps to Reproduce are in the description
    • NEW
    • NEW

    Description

      https://issues.redhat.com/browse/DROOLS-4288

      The problem is not fully solved, I got a forever loop on my KB since 7.21.0.Final, I tried with 7.25.0.Final but without success, and the issue is still here with 7.31.0.Final. Will go back to release 7.20.0.Final
      (the only fix I can apply is to add no-loop clause to my rules although it shouldn't be necessary).

      I can't share the affected KB, and unfortunately I was unable to reproduce the issue loop on a smaller example

      The affected rule looks like :

      {{rule "reset metric to max score when no more issues are present"
      //no-loop // TODO - no-loop TO BE REMOVED AS IT SHOULDN'T BE NECESSARY
      when
      Something($id:identity, $origin:origin)
      not Issue($id == identity, $origin == origin, category!="metrics")
      $scoring: Scoring(name == "performance", $id == identity, $origin == origin)
      then
      modify($scoring)

      { setValue(100.0); }

      end}}


      from https://issues.redhat.com/browse/DROOLS-4288 :

      When there is a version change in drools-compiler from `7.20.0.Final` to `7.21.0.Final` some rules are looping recursively.

      Code in github:

      The working version

      The recursively looping version

      The change between working and looping version

      More details

      When I fire a rule whose `then` part modifies a fact that is already checked in the `when` part:

      rule "rule 1.1"
        when
          $sampleDomain: SampleDomain(instanceVariable2 == "Value of instance variable")
        then
          System.out.println("Rule 1.1 fired");
          modify($sampleDomain){
          		setInstanceVariable1(3)
          }
      end
      

      it doesn't loop recursively.

      But when I call another rule which call a static function from another class:

      rule "rule 1.2"
        when
          $sampleDomain: SampleDomain(CoreUtils.anotherFunction())
        then
          System.out.println("Rule 1.2 fired");
          modify($sampleDomain){
          		setInstanceVariable1(3)
          }
      end
      

      it loops recursively.

      The class with static function is

      import com.drool_issue.domain.SampleDomain;
      
      public class CoreUtils {
      	
      	public static boolean anotherFunction() {
      		System.out.println("anotherFunction() inside CoreUtils");
      		return true;
      	}
      	
      	public static boolean anotherFunction(SampleDomain sampleDomain) {
      		System.out.println("anotherFunction(SampleDomain sampleDomain) inside CoreUtils");
      		return true;
      	}
      
      }
      

      My domain file is:

      public class SampleDomain {
      	private int instanceVariable1;
      	private String instanceVariable2;
      	private int instanceVariable3;
      	
      	
      	public int getInstanceVariable1() {
      		return instanceVariable1;
      	}
      	public void setInstanceVariable1(int instanceVariable1) {
      		this.instanceVariable1 = instanceVariable1;
      	}
      	public String getInstanceVariable2() {
      		return instanceVariable2;
      	}
      	public void setInstanceVariable2(String instanceVariable2) {
      		this.instanceVariable2 = instanceVariable2;
      	}
      	public int getInstanceVariable3() {
      		return instanceVariable3;
      	}
      	public void setInstanceVariable3(int instanceVariable3) {
      		this.instanceVariable3 = instanceVariable3;
      	}
      	
      	
      
      }
      

      This is only caused after version change from `7.20.0.Final` to `7.21.0.Final`. Any guess on what the problem might be?

      When I further looked into the problem I saw this too.

      When we add two functions into the `SampleDomain` class ie

          public boolean anotherFunction() {
      		return true;
      	}
      	
      	public boolean anotherFunction(SampleDomain sampleDomain) {
      		return true;
      	}
      

      and use this in the rule like:

      rule "rule 1.4"
        when
          $sampleDomain: SampleDomain(anotherFunction())
        then
          System.out.println("Rule 1.4 fired");
          modify($sampleDomain){
          		setInstanceVariable1(3)
          }
      end
      

      and

      rule "rule 1.5"
        when
          $sampleDomain: SampleDomain(anotherFunction($sampleDomain))
        then
          System.out.println("Rule 1.5 fired");
          modify($sampleDomain){
          		setInstanceVariable3(4)
          }
      end
      

      these also loops recursively.

      Code in github:

      The recursive looping when using non static methods

      The change between working and above version

      Also when any of the static method is made non static then method from the domain class is called even though the static method is specified in the rule.

      Code portions to be noted here are:

      Rule where static method is called.

      Another rule which also call the static method.

      The static access modifier removed from the functions which where previously static.

      Code in github:

      Weird behaviour when removing static modifier for the functions.

      The change between working and above version

      All this are caused in versions after `7.20.0.Final`, ie `7.21.0.Final`, `7.22.0.Final` and `7.23.0.Final`

      Attachments

        1. error.png
          error.png
          143 kB
        2. pojo.png
          pojo.png
          169 kB
        3. Screen Shot 2019-07-10 at 3.53.10 PM.png
          Screen Shot 2019-07-10 at 3.53.10 PM.png
          47 kB
        4. Screen Shot 2019-07-10 at 5.56.32 PM.png
          Screen Shot 2019-07-10 at 5.56.32 PM.png
          63 kB
        5. Screen Shot 2019-07-10 at 5.59.28 PM.png
          Screen Shot 2019-07-10 at 5.59.28 PM.png
          87 kB
        6. static_error.png
          static_error.png
          265 kB
        7. static.png
          static.png
          78 kB
        8. toto.drl
          1 kB

        Issue Links

          Activity

            People

              mfusco@redhat.com Mario Fusco
              davcro Crosson David (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: