[jboss-jira] [JBoss JIRA] Created: (JBRULES-1591) Newline in eval expression causes NullPointerException

Brian Stiles (JIRA) jira-events at lists.jboss.org
Mon Apr 28 13:57:17 EDT 2008


Newline in eval expression causes NullPointerException
------------------------------------------------------

                 Key: JBRULES-1591
                 URL: http://jira.jboss.com/jira/browse/JBRULES-1591
             Project: JBoss Drools
          Issue Type: Bug
      Security Level: Public (Everyone can see)
    Affects Versions: 4.0.7
            Reporter: Brian Stiles
         Assigned To: Mark Proctor


If a newline splits an eval expression, an NPE is thrown at org.drools.rule.PredicateConstraint.createContextEntry(PredicateConstraint.java:201).

The following code demonstrates the problem.  Removing the newline from the eval expression solves the problem.

--

package sample;

import java.io.StringReader;

import org.drools.RuleBase;
import org.drools.RuleBaseConfiguration;
import org.drools.RuleBaseFactory;
import org.drools.StatefulSession;
import org.drools.compiler.PackageBuilder;
import org.drools.compiler.PackageBuilderConfiguration;

public class ExpressionProblem {

    public static class Tester {

        public boolean test(Object o1, Object o2) {
            return o1.equals(o2);
        }
    }

    public static void main(String[] args) throws Exception {

        final PackageBuilderConfiguration packageBuilderConfiguration =
                new PackageBuilderConfiguration();
        final PackageBuilder packageBuilder = new PackageBuilder(packageBuilderConfiguration);

        packageBuilder.addPackageFromDrl(new StringReader("\n"
                + "package sample\n"
                + "\n"
                + "import sample.ExpressionProblem.Tester;\n"
                + "global sample.ExpressionProblem.Tester tester;\n"
                + "\n"
                + "rule MyRule\n"
                + "\n"
                + "    when\n"
                + "        Integer($f : this, eval(tester.test($f,\n" // OFFENDING NEWLINE
                + "                                          $f)))\n"
                + "    then \n"
                + "        System.out.println($f);\n"
                + "end \n"
                + ""));

        final RuleBaseConfiguration ruleBaseConfiguration = new RuleBaseConfiguration();
        final RuleBase ruleBase = RuleBaseFactory.newRuleBase(ruleBaseConfiguration);
        ruleBase.addPackage(packageBuilder.getPackage());
        final StatefulSession session = ruleBase.newStatefulSession(false);
        session.setGlobal("tester", new Tester());
        session.insert(1);
        session.fireAllRules();
    }
}



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list