[jboss-svn-commits] JBL Code SVN: r9607 - in labs/jbossrules/trunk: drools-compiler/src/test/resources/org/drools/integrationtests and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Feb 19 11:57:07 EST 2007
Author: tirelli
Date: 2007-02-19 11:57:07 -0500 (Mon, 19 Feb 2007)
New Revision: 9607
Added:
labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_emptyIdentifier.drl
Modified:
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Column.java
Log:
JBRULES-667: fixing NPE when cloning a pattern that has no identifier assigned
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java 2007-02-19 16:35:56 UTC (rev 9606)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java 2007-02-19 16:57:07 UTC (rev 9607)
@@ -3881,4 +3881,33 @@
}
+ public void testEmptyIdentifier() throws Exception {
+ try {
+ final PackageBuilder builder = new PackageBuilder();
+ builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_emptyIdentifier.drl" ) ) );
+ final Package pkg = builder.getPackage();
+
+ final RuleBase ruleBase = getRuleBase();
+ ruleBase.addPackage( pkg );
+ final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+ final List result = new ArrayList();
+ workingMemory.setGlobal( "results",
+ result );
+
+ final Person person = new Person("bob");
+ final Cheese cheese = new Cheese("brie", 10);
+
+ workingMemory.assertObject( person );
+ workingMemory.assertObject( cheese );
+
+ workingMemory.fireAllRules();
+ assertEquals( 4,
+ result.size() );
+
+ } catch ( Exception e ) {
+ e.printStackTrace();
+ fail("Should not raise any exception");
+ }
+ }
+
}
Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_emptyIdentifier.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_emptyIdentifier.drl (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_emptyIdentifier.drl 2007-02-19 16:57:07 UTC (rev 9607)
@@ -0,0 +1,33 @@
+package org.drools
+
+global java.util.List results;
+
+rule "Or condition followed by fact"
+ when
+ Cheese( type == "stilton" ) or Cheese( type == "brie" )
+ Person( )
+ then
+ results.add("Or condition followed by fact is ok");
+end
+
+rule "Fact followed by or condition"
+ when
+ Person( )
+ Cheese( type == "stilton" ) or Cheese( type == "brie" )
+ then
+ results.add("Fact followed by or condition is ok");
+end
+
+rule "Single fact"
+ when
+ Person( )
+ then
+ results.add("Single fact is ok");
+end
+
+rule "Single or"
+ when
+ Cheese( type == "stilton" ) or Cheese( type == "brie" )
+ then
+ results.add("Single or is ok");
+end
Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_emptyIdentifier.drl
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:eol-style
+ native
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Column.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Column.java 2007-02-19 16:35:56 UTC (rev 9606)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Column.java 2007-02-19 16:57:07 UTC (rev 9607)
@@ -69,7 +69,7 @@
this.index = index;
this.offset = offset;
this.objectType = objectType;
- if ( identifier != null ) {
+ if ( identifier != null && ( ! identifier.equals( "" ) ) ) {
this.declaration = new Declaration( identifier,
new ColumnExtractor( objectType ),
this );
@@ -81,7 +81,9 @@
}
public Object clone() {
- Column clone = new Column( this.index, this.objectType, this.declaration.getIdentifier() );
+ String identifier = (this.declaration != null) ? this.declaration.getIdentifier() : null;
+ Column clone = new Column( this.index, this.objectType, identifier );
+
for( Iterator it = this.constraints.iterator(); it.hasNext(); ) {
Object constr = it.next();
if( constr instanceof Declaration ) {
More information about the jboss-svn-commits
mailing list