[jboss-jira] [JBoss JIRA] (JBRULES-3392) strict mode evaluation taking interface instead of class

Mario Fusco (JIRA) jira-events at lists.jboss.org
Mon Mar 19 06:51:48 EDT 2012


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

Mario Fusco resolved JBRULES-3392.
----------------------------------

    Fix Version/s: 5.3.2.Final
                   5.4.0.CR1
       Resolution: Cannot Reproduce Bug


I tried the following but I couldn't reproduce the problem.
Am I missing something?

    public interface InterfaceA {
        InterfaceB getB();
    }

    public interface InterfaceB { }

    public static class ClassA implements InterfaceA {
        public ClassB getB() {
            return new ClassB();
        }
    }

    public static class ClassB implements InterfaceB {
        public String getId() {
            return "123";
        }
    }

    @Test
    public void testCovariance() throws Exception {
        // JBRULES-3392
        String str =
                "import org.drools.integrationtests.MiscTest.*\n" +
                "rule x\n" +
                "when\n" +
                "   $b : ClassB( )\n" +
                "   $a : ClassA( b.id == $b.id )\n" +
                "then\n" +
                "end\n";

        KnowledgeBase kbase = loadKnowledgeBaseFromString( str );
        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

        ksession.insert(new ClassA());
        ksession.insert(new ClassB());
        assertEquals(1, ksession.fireAllRules());
    }

                
> strict mode evaluation taking interface instead of class
> --------------------------------------------------------
>
>                 Key: JBRULES-3392
>                 URL: https://issues.jboss.org/browse/JBRULES-3392
>             Project: Drools
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>          Components: drools-compiler (expert)
>    Affects Versions: 5.3.1.Final
>         Environment: java 1.6.0_29 on windows 7
>            Reporter: Lubos Pechac
>            Assignee: Mario Fusco
>             Fix For: 5.3.2.Final, 5.4.0.CR1
>
>
> I am getting a compilation error with my drl, that worked in 5.0.1:
> Unable to Analyse Expression las.id == $las.id:
> [Error: unable to resolve method using strict-mode: piag.entityinterface.ILink.id()]
> [Near : {... las.id == $las.id ....}]
>                  ^
> [Line: 42, Column: 30] : [Rule name='rule1']
> here's the rule:
> rule "rule1"
> when
>   $las : Link(name == "GA1")
>   $pi : PayItem(las.id == $las.id, amount > 0, comparisonType == "ECHT")
> then ...
> interface ILink is empty:
> public interface ILink { }
> class Link extends ILink adds a few attributes including id, name, amount, comparisonType...
> interface IPayItem has this getter:
> public ILink getLas();
> class PayItem overrides this getter:
> @Override
> public Link getLas() {
>   return this.las;
> }
> It seems like drools is incorrectly treating $pi as IPayItem. IPayItem.getLas() returns ILink which does not have method id(), as the message says. But PayItem.getLas() returns Link which does have attribute id.
> I didn't specify anywhere that $pi is IPayItem so why does it do this?

--
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