[jboss-jira] [JBoss JIRA] Commented: (JBRULES-1591) Newline in eval expression causes NullPointerException
Julien Kronegg (JIRA)
jira-events at lists.jboss.org
Sat Sep 13 14:50:23 EDT 2008
[ https://jira.jboss.org/jira/browse/JBRULES-1591?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12429448#action_12429448 ]
Julien Kronegg commented on JBRULES-1591:
-----------------------------------------
We had the same exception by using an eval() written on more than one line, such as:
eval (
obj.isA() ||
obj.isB() ||
obj.isC()
)
The workaround was to write the eval() on one line:
eval ( obj.isA() || obj.isB() || obj.isC() )
But this is not really a good solution from the readability/maintenance viewpoint.
> Newline in eval expression causes NullPointerException
> ------------------------------------------------------
>
> Key: JBRULES-1591
> URL: https://jira.jboss.org/jira/browse/JBRULES-1591
> Project: JBoss Drools
> Issue Type: Bug
> Security Level: Public(Everyone can see)
> Affects Versions: 4.0.7
> Reporter: Brian Stiles
> Assignee: Edson Tirelli
> Fix For: 5.0.0.M2
>
>
> 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: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list