[jboss-jira] [JBoss JIRA] (DROOLS-809) NPE when using extend rules with or node and exists

Mario Fusco (JIRA) issues at jboss.org
Wed Aug 5 11:10:07 EDT 2015


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

Mario Fusco resolved DROOLS-809.
--------------------------------
    Resolution: Cannot Reproduce Bug


I'm not sure which commit fixed this issue (if any) but I couldn't reproduce that NPE on master. The test case I used to try to reproduce this problem (borrowed from the linked github project) follows:

{code}
    @Test
    public void testExtendRuleWithOr() {
        // DROOLS-809
        String drl =
                "import " + Customer.class.getCanonicalName() + "\n" +
                "import " + Car.class.getCanonicalName() + "\n" +
                "\n" +
                "rule \"base\"\n" +
                "when\n" +
                "    (\n" +
                "        (\n" +
                "            $car := Car( $customer := customer )\n" +
                "            and\n" +
                "            exists  Customer(  this == $customer, age > 50  )\n" +
                "        )\n" +
                "        or\n" +
                "        (\n" +
                "            $car := Car( $customer := customer )\n" +
                "            and\n" +
                "            exists  Customer(  this == $customer, age > 30  )\n" +
                "        )\n" +
                "    )\n" +
                "then\n" +
                "    System.out.println(\"rule\");\n" +
                "    System.out.println($customer);\n" +
                "    System.out.println($car);\n" +
                "end\n" +
                "\n" +
                "rule \"extended\" extends \"base\"\n" +
                "when\n" +
                "    $car := Car( customer == $customer )\n" +
                "then\n" +
                "    System.out.println(\"Extended rule\");\n" +
                "    System.out.println($car);\n" +
                "end\n";

        KieSession ksession = new KieHelper().addContent( drl, ResourceType.DRL )
                                             .build()
                                             .newKieSession();

        Customer c1     = new Customer( 85 );
        Car      car1   = new Car(c1);

        ksession.insert(c1);
        ksession.insert(car1);
        ksession.fireAllRules();
    }

    public static class Car {
        public Customer customer;

        public Car(){ }

        public Car(Customer customer) {
            this.customer = customer;
        }

        public Customer getCustomer() {
            return customer;
        }

        public void setCustomer(Customer customer) {
            this.customer = customer;
        }
    }

    public static class Customer {
        int age;
        double discount;
        boolean hasCar;

        public Customer() {
        }

        public Customer(int age ) {
            this.age = age;
        }

        public int getAge() {

            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public double getDiscount() {
            return discount;
        }

        public void setDiscount(double discount) {
            this.discount = discount;
        }

        public boolean getHasCar() {
            return hasCar;
        }

        public void setHasCar(boolean hasCar) {
            this.hasCar = hasCar;
        }
    }
{code}

> NPE when using extend rules with or node and exists
> ---------------------------------------------------
>
>                 Key: DROOLS-809
>                 URL: https://issues.jboss.org/browse/DROOLS-809
>             Project: Drools
>          Issue Type: Bug
>            Reporter: Jonathan MERCIER
>            Assignee: Mario Fusco
>
> Dear
> In some case extended rule failed to find  variable.
> {panel:title=NPE|borderStyle=dashed|borderColor=#ccc|titleBGColor=#F7D6C1|bgColor=#FFFFCE}
> Exception in thread "main" Exception executing consequence for rule "extended" in fr.cea.test: java.lang.NullPointerException
> 	at org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
> 	at org.drools.core.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1125)
> 	at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:160)
> 	at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:108)
> 	at org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1016)
> 	at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1302)
> 	at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1289)
> 	at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1262)
> 	at fr.cea.test.App.main(App.java:57)
> Caused by: java.lang.NullPointerException
> 	at fr.cea.test.Rule_extended1921345119DefaultConsequenceInvokerGenerated.evaluate(Unknown Source)
> 	at fr.cea.test.Rule_extended1921345119DefaultConsequenceInvoker.evaluate(Unknown Source)
> 	at org.drools.core.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1114)
> 	... 7 more
> {panel}
> This occur when using "or", "exists" and "extends" 
> A minimal test case is available on [github|https://github.com/bioinfornatics/DROOLS_NPE_rule_extended]
> In this [test case |https://github.com/bioinfornatics/DROOLS_NPE_rule_extended/blob/master/src/main/resources/fr.cea.test/rules.drl]:
>  if we comment line number 35 , any error are raised
>  if we uncomment line number 10 , any error are raised
>  if we remove all "exists" words, any error are raised
> If the same rule is write using named consequence the test pass.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


More information about the jboss-jira mailing list