NullPointerException When Using Conditional Element "or" in
LHS Together with a Return Value Restriction
--------------------------------------------------------------------------------------------------------
Key: JBRULES-2203
URL:
https://issues.jboss.org/browse/JBRULES-2203
Project: Drools
Issue Type: Bug
Security Level: Public(Everyone can see)
Components: drools-compiler (expert)
Affects Versions: 5.0.1.FINAL
Environment: Drools 5.0.1 used in an Eclipse Drools project under Windows XP with
Java 1.6
Reporter: Christian Spurk
Assignee: Edson Tirelli
Fix For: 5.2.0.CR1
When using the conditional element "or" on the left hand side of a rule
together with a return value restriction somewhere in the same rule, I get the following
exception:
Exception in thread "main" java.lang.NullPointerException
at org.drools.rule.ReturnValueRestriction.equals(ReturnValueRestriction.java:304)
at org.drools.rule.ReturnValueConstraint.equals(ReturnValueConstraint.java:121)
at org.drools.reteoo.AlphaNode.equals(AlphaNode.java:218)
at
org.drools.reteoo.SingleObjectSinkAdapter.getMatchingNode(SingleObjectSinkAdapter.java:48)
at org.drools.reteoo.builder.BuildUtils.attachNode(BuildUtils.java:130)
at org.drools.reteoo.builder.PatternBuilder.attachAlphaNodes(PatternBuilder.java:295)
at org.drools.reteoo.builder.PatternBuilder.attachPattern(PatternBuilder.java:117)
at org.drools.reteoo.builder.PatternBuilder.build(PatternBuilder.java:70)
at
org.drools.reteoo.builder.GroupElementBuilder$AndBuilder.build(GroupElementBuilder.java:126)
at org.drools.reteoo.builder.GroupElementBuilder.build(GroupElementBuilder.java:73)
at org.drools.reteoo.builder.ReteooRuleBuilder.addSubRule(ReteooRuleBuilder.java:153)
at org.drools.reteoo.builder.ReteooRuleBuilder.addRule(ReteooRuleBuilder.java:126)
at org.drools.reteoo.ReteooBuilder.addRule(ReteooBuilder.java:117)
at org.drools.reteoo.ReteooRuleBase.addRule(ReteooRuleBase.java:362)
at org.drools.common.AbstractRuleBase.addRule(AbstractRuleBase.java:618)
at org.drools.common.AbstractRuleBase.addPackages(AbstractRuleBase.java:500)
at org.drools.reteoo.ReteooRuleBase.addPackages(ReteooRuleBase.java:379)
at org.drools.impl.KnowledgeBaseImpl.addKnowledgePackages(KnowledgeBaseImpl.java:121)
at com.sample.DroolsTest.readKnowledgeBase(DroolsTest.java:48)
at com.sample.DroolsTest.main(DroolsTest.java:26)
Here is a simple test case which can be used to reproduce the issue:
/* JAVA FILE TO LOAD THE RULE */
package com.sample;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderError;
import org.drools.builder.KnowledgeBuilderErrors;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
public class DroolsTest {
private int arg;
public int getArg() {
return this.arg;
}
public void setArg(int arg) {
this.arg = arg;
}
public static final void main(String[] args) throws Exception {
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
DroolsTest test = new DroolsTest();
test.setArg(2);
ksession.insert(test);
ksession.fireAllRules();
}
/* taken verbatim from the Hello World sample */
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("Sample.drl"),
ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase;
}
}
/* PROBLEMATIC RULE FILE */
package com.sample
import com.sample.DroolsTest;
rule "test"
when
DroolsTest( arg == (1 + 1) );
// REMOVE THE COMMENTED PARTS BELOW TO GET THE EXCEPTION:
//(or eval(true);
eval(true);
//)
then
System.out.println( "it works!" );
end
When the above Java file is compiled and run in combination with the given rule file,
everything works fine. However, if the marked parts of the rule are uncommented, then you
get the exception.
PS: It seems that the issue has been existing in previous Drools versions already, see
https://jira.jboss.org/jira/browse/JBSEAM-3064 for example ("Drools 4.0.7 don't
like 'action == (DocumentType.USER.extendedName())' and multiple OR's -
weird!").
--
This message is automatically generated by JIRA.
For more information on JIRA, see: