[jboss-jira] [JBoss JIRA] (JBRULES-3240) Unable to build expression for 'inline-eval' when using Lists of objects

Richard Ambridge (Updated) (JIRA) jira-events at lists.jboss.org
Mon Oct 10 05:42:16 EDT 2011


     [ https://issues.jboss.org/browse/JBRULES-3240?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Richard Ambridge updated JBRULES-3240:
--------------------------------------

    Workaround Description: 
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

  was:Works in 5.1.1 release


    
> Unable to build expression for 'inline-eval' when using Lists of objects
> ------------------------------------------------------------------------
>
>                 Key: JBRULES-3240
>                 URL: https://issues.jboss.org/browse/JBRULES-3240
>             Project: Drools
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>          Components: drools-compiler
>    Affects Versions: 5.3.0.CR1
>         Environment: Ubuntu, JDK 1.6.0.26
>            Reporter: Richard Ambridge
>            Assignee: Mark Proctor
>
> 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 {
>         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)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the jboss-jira mailing list