[jboss-svn-commits] JBL Code SVN: r8315 - in labs/jbossrules/trunk/drools-compiler/src: main/java/org/drools/semantics/java test/java/org/drools/integrationtests test/resources/org/drools/integrationtests
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Dec 14 11:02:32 EST 2006
Author: tirelli
Date: 2006-12-14 11:02:20 -0500 (Thu, 14 Dec 2006)
New Revision: 8315
Added:
labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_missing_import.drl
Modified:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/RuleBuilder.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java
Log:
JBRULES-579: fixing NPE when not able to resolve object types for 'from', 'collect' and 'accumulate' constructs
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/RuleBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/RuleBuilder.java 2006-12-14 12:16:44 UTC (rev 8314)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/RuleBuilder.java 2006-12-14 16:02:20 UTC (rev 8315)
@@ -314,13 +314,19 @@
}
} else if ( object.getClass() == FromDescr.class ) {
final From from = build( (FromDescr) object );
- this.rule.addPattern( from );
+ if( from != null ) {
+ this.rule.addPattern( from );
+ }
} else if ( object.getClass() == AccumulateDescr.class ) {
final Accumulate accumulate = build( (AccumulateDescr) object );
- this.rule.addPattern( accumulate );
+ if( accumulate != null ) {
+ this.rule.addPattern( accumulate );
+ }
} else if ( object.getClass() == CollectDescr.class ) {
final Collect collect = build( (CollectDescr) object );
- this.rule.addPattern( collect );
+ if( collect != null ) {
+ this.rule.addPattern( collect );
+ }
}
} else if ( object.getClass() == ColumnDescr.class ) {
final Column column = build( (ColumnDescr) object );
@@ -983,6 +989,11 @@
private From build(final FromDescr fromDescr) {
final Column column = build( fromDescr.getReturnedColumn() );
+
+ if( column == null ) {
+ return null;
+ }
+
AccessorDescr accessor = (AccessorDescr) fromDescr.getDataSource();
DataProvider dataProvider = null;
try {
@@ -1242,6 +1253,10 @@
this.innerDeclarations = new HashMap();
Column sourceColumn = build( accumDescr.getSourceColumn() );
+
+ if( sourceColumn == null ) {
+ return null;
+ }
// remove declarations bound inside source column
this.declarations.keySet().removeAll( this.innerDeclarations.keySet() );
Map sourceDeclarations = this.innerDeclarations;
@@ -1348,6 +1363,11 @@
private Collect build(final CollectDescr collectDescr) {
this.innerDeclarations = new HashMap();
Column sourceColumn = build( collectDescr.getSourceColumn() );
+
+ if( sourceColumn == null ) {
+ return null;
+ }
+
// remove declarations bound inside source column
this.declarations.keySet().removeAll( this.innerDeclarations.keySet() );
this.innerDeclarations = null;
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 2006-12-14 12:16:44 UTC (rev 8314)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java 2006-12-14 16:02:20 UTC (rev 8315)
@@ -74,6 +74,7 @@
import org.drools.integrationtests.helloworld.Message;
import org.drools.lang.DrlDumper;
import org.drools.lang.descr.PackageDescr;
+import org.drools.rule.InvalidRulePackage;
import org.drools.rule.Package;
import org.drools.rule.Rule;
import org.drools.spi.ActivationGroup;
@@ -3611,4 +3612,21 @@
}
}
+
+ public void testMissingImports() {
+ try {
+ final PackageBuilder builder = new PackageBuilder();
+ builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_missing_import.drl" ) ) );
+ final Package pkg = builder.getPackage();
+
+ final RuleBase ruleBase = getRuleBase();
+ ruleBase.addPackage( pkg );
+
+ Assert.fail("Should have thrown an InvalidRulePackage");
+ } catch ( InvalidRulePackage e ) {
+ // everything fine
+ } catch ( Exception e ) {
+ Assert.fail("Should have thrown an InvalidRulePackage Exception instead of "+e.getMessage());
+ }
+ }
}
Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_missing_import.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_missing_import.drl 2006-12-14 12:16:44 UTC (rev 8314)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_missing_import.drl 2006-12-14 16:02:20 UTC (rev 8315)
@@ -0,0 +1,8 @@
+package foo;
+
+rule "Generates NPE"
+ when
+ $count : Thing( size > 0 ) from collect( Gizmo( length == 1 ) )
+ then
+ System.out.println("boo");
+end
\ No newline at end of file
Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_missing_import.drl
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:eol-style
+ native
More information about the jboss-svn-commits
mailing list