[jboss-jira] [JBoss JIRA] (DROOLS-770) Query order can to lead to a NPE
Jonathan MERCIER (JIRA)
issues at jboss.org
Thu Apr 23 04:47:33 EDT 2015
Jonathan MERCIER created DROOLS-770:
---------------------------------------
Summary: Query order can to lead to a NPE
Key: DROOLS-770
URL: https://issues.jboss.org/browse/DROOLS-770
Project: Drools
Issue Type: Bug
Reporter: Jonathan MERCIER
Assignee: Mark Proctor
Priority: Critical
This bug is already reported to the drools team via email on 13th february.
To follow efficiently any progress on this critical bug, I open a ticket.
So, the reproducer code is:
{code:java|title=NpeOnQueryTest|borderStyle=solid}
package org.drools.compiler.integrationtests;
import org.junit.Test;
import org.kie.api.io.ResourceType;
import org.kie.api.runtime.KieSession;
import org.kie.internal.utils.KieHelper;
import java.util.List;
public class NpeOnQueryTest {
@Test
public void test() {
String drl =
"import " + FiveState.class.getCanonicalName() + ";\n" +
"import " + NodeType.class.getCanonicalName() + ";\n" +
"import " + Knowledge.class.getCanonicalName() + ";\n" +
"import " + List.class.getCanonicalName() + ";\n" +
"\n" +
"rule \"Or Knowledge is unknown\"\n" +
" when\n" +
" $k: Knowledge( presence == FiveState.UNEVALUATED, nodeType == NodeType.OR )\n" +
" allSubKnowledgeAreEvaluated( $k, $childs; )\n" +
" not( Knowledge( presence == FiveState.TRUE ) )\n" +
" then\n" +
" modify( $k ){\n" +
" setPresence( FiveState.UNKNOWN )\n" +
" }\n" +
"end\n" +
"\n" +
"rule \"Or Knowledge is present\"\n" +
" when\n" +
" $k: Knowledge( presence == FiveState.UNEVALUATED, nodeType == NodeType.OR )\n" +
" allSubKnowledgeAreEvaluated( $k, $childs; )\n" +
" then\n" +
" modify( $k ){\n" +
" setPresence( FiveState.TRUE )\n" +
" }\n" +
"end\n" +
"\n" +
"query allSubKnowledgeAreEvaluated( Knowledge parent, List childs )\n" +
" childs:= List() from collect ( Knowledge( parent memberOf partOf ))\n" +
" forall( Knowledge( presence != FiveState.UNEVALUATED ) from childs )\n" +
"end\n";
KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL)
.build()
.newKieSession();
Knowledge bk0 = new Knowledge(new Knowledge[0], NodeType.OR, "bk0", FiveState.UNEVALUATED);
Knowledge bk1 = new Knowledge(new Knowledge[] { bk0 }, NodeType.LEAF, "bk1", FiveState.TRUE);
ksession.insert( bk0 );
ksession.insert( bk1 );
ksession.fireAllRules();
}
public enum FiveState {
TRUE,
FALSE,
BOTH,
UNKNOWN,
UNEVALUATED
}
public enum NodeType {
LEAF,
AND,
OR
}
public static class Knowledge {
private final Knowledge[] partOf;
private final NodeType nodeType;
private final String name;
private FiveState presence;
public Knowledge(Knowledge[] partOf, NodeType nodeType, String name, FiveState presence) {
this.partOf = partOf;
this.nodeType = nodeType;
this.name = name;
this.presence = presence;
}
public void setPresence(final FiveState presence) {
this.presence = presence;
}
public String getName() {
return name;
}
public FiveState getPresence() {
return presence;
}
public NodeType getNodeType() {
return nodeType;
}
public Knowledge[] getPartOf() {
return partOf;
}
}
}
{code}
The interesting thing to be noticed is that if I move the query before the 2 rules in that DRL the problem disappears.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
More information about the jboss-jira
mailing list