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

Unable to build expression for 'inline-eval' when using Lists of objects

    XMLWordPrintable

Details

    • Hide

      Works in 5.1.1 release

      The issue is when the items!=null || is in the rule

      Setting:
      $m : MyItem( items.size == 0) <-- works
      $m : MyItem( items != null, items.size == 0) <-- works (but not correct, we are AND instead of OR
      $m : MyItem( items != null || getItems().isEmpty()) <-- works
      $m : MyItem( items != null || items.size == 0) <-- Fails

      Show
      Works in 5.1.1 release The issue is when the items!=null || is in the rule Setting: $m : MyItem( items.size == 0) <-- works $m : MyItem( items != null, items.size == 0) <-- works (but not correct, we are AND instead of OR $m : MyItem( items != null || getItems().isEmpty()) <-- works $m : MyItem( items != null || items.size == 0) <-- Fails

    Description

      If a Rule has a .size== in when and the variable is an Object, then we get the following:-
      Unable to build expression for 'inline-eval' : [Error: incompatible types in statement: class java.lang.Integer (compared from: class droolstesting.SubType)]

      Full example:

      Rule:

      package droolstesting

      rule "rule2"
      dialect "mvel"
      when
      $m : MyItem(items!=null || items.size == 0)
      then
      System.out.println("Got 0");
      retract($m)
      end

      MyItems.java:

      package droolstesting;

      import java.util.ArrayList;
      import java.util.List;

      public class MyItem {
      int number=0;
      String string="empty";

      List<SubType> items=new ArrayList<SubType>();

      public List<SubType> getItems()

      { return items; }

      public void setItems(List<SubType> items)

      { this.items = items; }

      public int getNumber()

      { return number; }

      public void setNumber(int number)

      { this.number = number; }

      public String getString()

      { return string; }

      public void setString(String string)

      { this.string = string; }

      }

      SubType.java:
      package droolstesting;
      public class SubType {
      String name="";

      }

      Main.java:
      package droolstesting;

      import java.io.File;
      import java.io.IOException;
      import org.drools.compiler.DroolsParserException;
      import org.drools.compiler.PackageBuilder;
      import org.drools.io.ResourceFactory;

      /**
      *

      • @author richarda
        */
        public class Main {

      /**

      • @param args the command line arguments
        */
        public static void main(String[] args) throws IOException, DroolsParserException
        Unknown macro: { PackageBuilder pkgBuilder = new PackageBuilder(); pkgBuilder.addPackageFromDrl(ResourceFactory.newClassPathResource("rule1.drl")); if (pkgBuilder.hasErrors()) { System.err.println(pkgBuilder.getErrors().toString()); throw new RuntimeException("Unable to compile rules"); }
        pkgBuilder.addPackageFromDrl(ResourceFactory.newClassPathResource("rule2.drl"));
        if (pkgBuilder.hasErrors()) { System.err.println(pkgBuilder.getErrors().toString()); throw new RuntimeException("Unable to compile rules"); } }

        }

      Result:

      run:
      Unable to build expression for 'inline-eval' : [Error: incompatible types in statement: class java.lang.Integer (compared from: class droolstesting.SubType)]
      [Near :

      {... items != null || items.size == 0 ....}]
      ^
      [Line: 6, Column: 14]'items != null || items.size == 0'
      [Error: incompatible types in statement: class java.lang.Integer (compared from: class droolstesting.SubType)]
      [Near : {... items != null || items.size == 0 ....}

      ]
      ^
      [Line: 6, Column: 14] : [Rule name='rule2']
      [Error: incompatible types in statement: class java.lang.Integer (compared from: class droolstesting.SubType)]
      [Near :

      {... items != null || items.size == 0 ....}

      ]
      ^
      [Line: 1, Column: 18]

      Exception in thread "main" java.lang.RuntimeException: Unable to compile rules
      at droolstesting.Main.main(Main.java:32)
      Java Result: 1
      BUILD SUCCESSFUL (total time: 1 second)

      Attachments

        Activity

          People

            mfusco@redhat.com Mario Fusco
            richardambridge_jira Richard Ambridge (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: