[
http://jira.jboss.com/jira/browse/JBRULES-515?page=all ]
Edson Tirelli closed JBRULES-515.
---------------------------------
Resolution: Done
Final fix commited into trunk in revision #7592. Now one can use (and mix) both previously
bound variables and variables bound in the same pattern when using predicates and return
value constraints, as well as the direct variable use.
Sending drools-compiler/src/main/java/org/drools/semantics/java/RuleBuilder.java
Sending
drools-compiler/src/main/resources/org/drools/semantics/java/javaInvokers.stg
Sending drools-compiler/src/main/resources/org/drools/semantics/java/javaRule.stg
Sending
drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java
Sending drools-compiler/src/test/java/org/drools/integrationtests/ReteTest.java
Sending
drools-compiler/src/test/resources/org/drools/integrationtests/test_DeclaringAndUsingBindsInSamePattern.drl
Sending drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
Sending drools-core/src/main/java/org/drools/RuleBaseFactory.java
Sending drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
Sending drools-core/src/main/java/org/drools/rule/PredicateConstraint.java
Sending drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java
Sending drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java
Sending drools-core/src/main/java/org/drools/spi/PredicateExpression.java
Sending drools-core/src/main/java/org/drools/spi/ReturnValueExpression.java
Transmitting file data ..............
Committed revision 7592.
Test case added.
java NullPointerException when using constraints between fields in
same object
------------------------------------------------------------------------------
Key: JBRULES-515
URL:
http://jira.jboss.com/jira/browse/JBRULES-515
Project: JBoss Rules
Issue Type: Bug
Security Level: Public(Everyone can see)
Affects Versions: 3.0.4
Environment: Linux
Reporter: Sridhar Chandrasekharan
Assigned To: Edson Tirelli
Fix For: 3.1-m1
Consider the following files:-
1) Foo.java
package com.foo;
public class Foo {
private int a;
private int b;
public Foo(int a, int b) {
super();
this.a = a;
this.b = b;
}
public boolean test()
{
return (a > b);
}
public int getA() {
return a;
}
public int getB() {
return b;
}
}
******************************************************************************
2) FooTest.java
package com.foo;
import java.io.InputStreamReader;
import java.io.*;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.compiler.PackageBuilder;
import org.drools.rule.Package;
public class FooTest {
/**
* This is a sample file to launch a rule package from a rule source file.
*/
public static final void main(String[] args) {
try {
//load up the rulebase
RuleBase ruleBase = readRule();
WorkingMemory workingMemory = ruleBase.newWorkingMemory();
//go !
workingMemory.fireAllRules();
} catch (Throwable t) {
t.printStackTrace();
}
}
/**
* Please note that this is the "low level" rule assembly API.
*/
private static RuleBase readRule() throws Exception {
//read in the source
Reader source = new InputStreamReader( FooTest.class.getResourceAsStream(
"/Foo.drl" ) );
//optionally read in the DSL (if you are using it).
//Reader dsl = new InputStreamReader( DroolsTest.class.getResourceAsStream(
"/mylang.dsl" ) );
//Use package builder to build up a rule package.
//An alternative lower level class called "DrlParser" can also be used...
PackageBuilder builder = new PackageBuilder();
//this wil parse and compile in one step
//NOTE: There are 2 methods here, the one argument one is for normal DRL.
builder.addPackageFromDrl( source );
//Use the following instead of above if you are using a DSL:
//builder.addPackageFromDrl( source, dsl );
//get the compiled package (which is serializable)
Package pkg = builder.getPackage();
//add the package to a rulebase (deploy the rule package).
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkg );
return ruleBase;
}
}
***************************************************
3) Foo.drl
package com.foo
rule "Initialization rule"
when
#conditions
then
assert(new Foo(1,1));
assert(new Foo(2,1));
assert(new Foo(2,3));
assert(new Foo(3,2));
assert(new Foo(3,4));
assert(new Foo(4,3));
end
rule "a greater than b"
when
f : Foo(x : a, b < x)
then
System.out.println("a=" + f.getA() + " b=" + f.getB() );
end
******************************************
I get the following error when running the program
java.lang.NullPointerException
at org.drools.rule.BoundVariableConstraint.isAllowed(Unknown Source)
at org.drools.common.BetaNodeBinder.isAllowed(Unknown Source)
at org.drools.reteoo.LeftInputAdapterNode.assertObject(Unknown Source)
at org.drools.reteoo.ObjectSource.propagateAssertObject(Unknown Source)
at org.drools.reteoo.ObjectTypeNode.assertObject(Unknown Source)
at org.drools.reteoo.Rete.assertObject(Unknown Source)
at org.drools.reteoo.ReteooRuleBase.assertObject(Unknown Source)
at org.drools.reteoo.ReteooWorkingMemory.doAssertObject(Unknown Source)
at org.drools.common.AbstractWorkingMemory.assertObject(Unknown Source)
at org.drools.base.DefaultKnowledgeHelper.assertObject(Unknown Source)
at org.drools.base.DefaultKnowledgeHelper.assertObject(Unknown Source)
at com.foo.Rule_Initialization_rule_0.consequence(Rule_Initialization_rule_0.java:7)
at
com.foo.Rule_Initialization_rule_0ConsequenceInvoker.evaluate(Rule_Initialization_rule_0ConsequenceInvoker.java:18)
at org.drools.common.DefaultAgenda.fireActivation(Unknown Source)
at org.drools.common.DefaultAgenda.fireNextItem(Unknown Source)
at org.drools.common.AbstractWorkingMemory.fireAllRules(Unknown Source)
at org.drools.common.AbstractWorkingMemory.fireAllRules(Unknown Source)
at com.foo.FooTest.main(FooTest.java:27)
org.drools.spi.ConsequenceException: java.lang.NullPointerException
at org.drools.common.DefaultAgenda.fireActivation(Unknown Source)
at org.drools.common.DefaultAgenda.fireNextItem(Unknown Source)
at org.drools.common.AbstractWorkingMemory.fireAllRules(Unknown Source)
at org.drools.common.AbstractWorkingMemory.fireAllRules(Unknown Source)
at com.foo.FooTest.main(FooTest.java:27)
Caused by: java.lang.NullPointerException
at org.drools.rule.BoundVariableConstraint.isAllowed(Unknown Source)
at org.drools.common.BetaNodeBinder.isAllowed(Unknown Source)
at org.drools.reteoo.LeftInputAdapterNode.assertObject(Unknown Source)
at org.drools.reteoo.ObjectSource.propagateAssertObject(Unknown Source)
at org.drools.reteoo.ObjectTypeNode.assertObject(Unknown Source)
at org.drools.reteoo.Rete.assertObject(Unknown Source)
at org.drools.reteoo.ReteooRuleBase.assertObject(Unknown Source)
at org.drools.reteoo.ReteooWorkingMemory.doAssertObject(Unknown Source)
at org.drools.common.AbstractWorkingMemory.assertObject(Unknown Source)
at org.drools.base.DefaultKnowledgeHelper.assertObject(Unknown Source)
at org.drools.base.DefaultKnowledgeHelper.assertObject(Unknown Source)
at com.foo.Rule_Initialization_rule_0.consequence(Rule_Initialization_rule_0.java:7)
at
com.foo.Rule_Initialization_rule_0ConsequenceInvoker.evaluate(Rule_Initialization_rule_0ConsequenceInvoker.java:18)
... 5 more
If I change the 2nd rule to
rule "a greater than b"
when
f : Foo()
and eval(f.test())
then
System.out.println("a=" + f.getA() + " b=" + f.getB() );
end
It works as expected.
--
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