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

Unexpected node sharing by function with equals

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • None
    • 7.17.0.Final
    • core engine

    Description

      Under the condition:

      • LHS has a constraint which calls a function
      • The function's argument contains "=="
      • The constraint itself uses "==" for comparison

      So the rules look like this:

      package com.sample
      import org.drools.compiler.Person;
      function int myFunction(String expression, int value) {
        if (expression.equals("param == 10") && value == 10) {
          return 1;
        }
        return 0;
      }
      rule R1
          when
              $p: Person(myFunction("param == 10", age) == 1)
          then
      end
      
      rule R2
          when
              $p: Person(myFunction("param == 20", age) == 1)
          then
      end
      

      In this case, AlphaNodes are shared so both rules match against a fact which should match only R1 (Person(age = 10)).

      Dump by ReteDumper

      [EntryPointNode(1) EntryPoint::DEFAULT ] on Partition(MAIN)
          [ObjectTypeNode(2)::EntryPoint::DEFAULT objectType=[ClassObjectType class=org.drools.core.reteoo.InitialFactImpl] expiration=-1ms ] on Partition(MAIN)
          [ObjectTypeNode(3)::EntryPoint::DEFAULT objectType=[ClassObjectType class=org.drools.compiler.Person] expiration=-1ms ] on Partition(MAIN)
              [AlphaNode(4) constraint=myFunction("param == 10", age) == 1] on Partition(1) d 0 i 0
                  [LeftInputAdapterNode(5)] on Partition(1) Ld 0 Li 0
                      [RuleTerminalNode(6): rule=R1] on Partition(1) d 0 i 0
                      [RuleTerminalNode(7): rule=R2] on Partition(1) d 0 i 0
      

      It seems to relate to MvelConstraint.equals() logic. (It doesn't take account of the text between "==" and "==")

      https://github.com/kiegroup/drools/blob/master/drools-core/src/main/java/org/drools/core/rule/constraint/MvelConstraint.java#L615-L616

      Attachments

        Issue Links

          Activity

            People

              mfusco@redhat.com Mario Fusco
              rhn-support-tkobayas Toshiya Kobayashi
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: