[jboss-jira] [JBoss JIRA] Created: (JBRULES-2282) Using "extends" with a $var in the parent causes Internal Error
Jeremy Ary (JIRA)
jira-events at lists.jboss.org
Tue Sep 22 09:44:49 EDT 2009
Using "extends" with a $var in the parent causes Internal Error
---------------------------------------------------------------
Key: JBRULES-2282
URL: https://jira.jboss.org/jira/browse/JBRULES-2282
Project: Drools
Issue Type: Bug
Security Level: Public (Everyone can see)
Components: drools-compiler
Affects Versions: 5.0.1.FINAL
Environment: Win XP SP3, Drools 5.0.1
Reporter: Jeremy Ary
Assignee: Mark Proctor
TEST CASE (DRL):
package org.drools.test;
import org.drools.Cheese;
import org.drools.Cheesery
global java.util.List list;
global Cheesery cheesery;
rule "test A"
when
$a: Cheese ( type == "stilton" )
then
list.add( new String ("rule A") );
end
rule "test B" extends "test A"
when
$b: Cheese ( type == "cheddar" )
$c: Cheese ( type == "brie" )
then
$a.setType( $c.getType() );
//list.add( $a.getType() );
list.add( new String ("rule B") );
end
TEST CASE (JAVA):
public void testExtends() throws Exception {
final PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "extend_rule_test.drl" ) ) );
final Package pkg = builder.getPackage();
RuleBase ruleBase = getRuleBase();
ruleBase.addPackage( pkg );
ruleBase = SerializationHelper.serializeObject(ruleBase);
final WorkingMemory workingMemory = ruleBase.newStatefulSession();
final List list = new ArrayList();
workingMemory.setGlobal( "list",
list );
final Cheese stilton = new Cheese( "stilton", 5 );
final Cheese cheddar = new Cheese( "cheddar", 7 );
final Cheese brie = new Cheese( "brie", 5 );
final FactHandle stiltonHandle = workingMemory.insert( stilton );
final FactHandle cheddarHandle = workingMemory.insert( cheddar );
final FactHandle brieHandle = workingMemory.insert( brie );
workingMemory.fireAllRules();
System.out.println(list);
assertTrue( list.size() > 0 );
}
Full stack trace:
org.drools.rule.InvalidRulePackage: Internal Error : Unable to find declaration in list while generating the consequence invoker : [Rule name='test B']
at org.drools.rule.Package.checkValidity(Package.java:477)
at org.drools.common.AbstractRuleBase.addPackages(AbstractRuleBase.java:435)
at org.drools.reteoo.ReteooRuleBase.addPackage(ReteooRuleBase.java:389)
at org.drools.integrationtests.ExtendsTest.testExtends(ExtendsTest.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
We debugged the test and traced the error back to a call to checkValidity() in AbstractRuleBase.java around like 435. If we comment out this call, we can continue with the debug and see that the three variables appear to be properly placed on the child rule object, but not before the validation check. However, running this way leads to a separate error and stack trace.
org.drools.runtime.rule.ConsequenceException: java.lang.ArrayIndexOutOfBoundsException: -1
at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:23)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:943)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:885)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1086)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:660)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:627)
at org.drools.integrationtests.ExtendsTest.testExtends(ExtendsTest.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
at org.drools.test.Rule_test_B_0ConsequenceInvoker.evaluate(Rule_test_B_0ConsequenceInvoker.java:20)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:934)
... 21 more
--
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