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

Using Java 8 stream lambda in RHS leads to compilation error

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 7.32.0.Final, 7.49.0.Final
    • None
    • None
    • Hide

      Example rule: (I've added a complete Eclipse minimal maven project setup zipped as an attachment)

      //created on: 12.02.2021//created on: 12.02.2021package demo
      //list any import classes here.import demo.SomeClass;import demo.SomeOtherClass;

      rule "FailsCompilation"    when        $some : SomeClass( getText().equals("Irrelevant") )        $other : SomeOtherClass()    then       $some.getReferences().stream()        .forEach(s -> {        s.setText("AlsoIrrelevant");        }); $other.setText("YouguessedIt");end

      rule "OkCompilation"    when        $some : SomeClass( getText().equals("Irrelevant") )        $other : SomeOtherClass()    then    $other.setText("YouguessedIt");       $some.getReferences().stream()        .forEach(s -> {        s.setText("AlsoIrrelevant");        }); $other.setText("YouguessedIt2");end

       

      Show
      Example rule: (I've added a complete Eclipse minimal maven project setup zipped as an attachment) //created on: 12.02.2021//created on: 12.02.2021package demo //list any import classes here.import demo.SomeClass;import demo.SomeOtherClass; rule "FailsCompilation"    when        $some : SomeClass( getText().equals("Irrelevant") )        $other : SomeOtherClass()    then       $some.getReferences().stream()        .forEach(s -> {        s.setText("AlsoIrrelevant");        }); $other.setText("YouguessedIt");end rule "OkCompilation"    when        $some : SomeClass( getText().equals("Irrelevant") )        $other : SomeOtherClass()    then    $other.setText("YouguessedIt");       $some.getReferences().stream()        .forEach(s -> {        s.setText("AlsoIrrelevant");        }); $other.setText("YouguessedIt2");end  
    • Undefined
    • NEW
    • NEW
    • ---
    • ---

      When using a lambda expression in the left hand side, any variable that is first used after the lambda expression is not added as a method parameter of (defaultConsequence), and leads to error of the following type:

      Exception in thread "main" java.lang.RuntimeException: Rule Base Build Errors:Exception in thread "main" java.lang.RuntimeException: Rule Base Build Errors:Error Messages:Message [id=1, kieBase=defaultKieBase, level=ERROR, path=rules/demo.drl, line=9, column=0   text=Rule Compilation error $other cannot be resolved]--Warning Messages:--Info Messages:
      at demo.StartDemo.createKsessionFromFiles(StartDemo.java:51) at demo.StartDemo.main(StartDemo.java:20)

              lmolteni@redhat.com Luca Molteni
              cmayrdorn Christoph Mayr-Dorn (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated: