[jboss-svn-commits] JBL Code SVN: r15730 - labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Oct 10 16:24:15 EDT 2007
Author: mark.proctor at jboss.com
Date: 2007-10-10 16:24:15 -0400 (Wed, 10 Oct 2007)
New Revision: 15730
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeObjectSinkAdapter.java
Log:
JBRULES-1264 NPE at BaseObjectClassFieldExtractor.getLongValue with null fields
-Added fix and integration test
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeObjectSinkAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeObjectSinkAdapter.java 2007-10-10 19:11:11 UTC (rev 15729)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeObjectSinkAdapter.java 2007-10-10 20:24:15 UTC (rev 15730)
@@ -67,7 +67,7 @@
final FieldIndex fieldIndex = registerFieldIndex( index,
literalConstraint.getFieldExtractor() );
- if ( fieldIndex.getCount() >= this.alphaNodeHashingThreshold ) {
+ if ( fieldIndex.getCount() >= this.alphaNodeHashingThreshold && this.alphaNodeHashingThreshold != 0) {
if ( !fieldIndex.isHashed() ) {
hashSinks( fieldIndex );
}
@@ -430,6 +430,8 @@
private long lvalue;
private boolean bvalue;
private double dvalue;
+
+ private boolean isNull;
private int hashCode;
@@ -459,46 +461,84 @@
final Extractor extractor) {
this.index = index;
final ValueType vtype = extractor.getValueType();
+
+ isNull = extractor.isNullValue(null, value);
+
if ( vtype.isBoolean() ) {
- this.bvalue = extractor.getBooleanValue( null, value );
this.type = BOOL;
- this.setHashCode( this.bvalue ? 1231 : 1237 );
+ if ( !isNull ) {
+ this.bvalue = extractor.getBooleanValue( null, value );
+ this.setHashCode( this.bvalue ? 1231 : 1237 );
+ } else {
+ this.setHashCode( 0 );
+ }
} else if ( vtype.isIntegerNumber() ) {
- this.lvalue = extractor.getLongValue( null, value );
this.type = LONG;
- this.setHashCode( (int) (this.lvalue ^ (this.lvalue >>> 32)) );
+ if ( !isNull ) {
+ this.lvalue = extractor.getLongValue( null, value );
+ this.setHashCode( (int) (this.lvalue ^ (this.lvalue >>> 32)) );
+ } else {
+ this.setHashCode( 0 );
+ }
} else if ( vtype.isFloatNumber() ) {
- this.dvalue = extractor.getDoubleValue( null, value );
this.type = DOUBLE;
- final long temp = Double.doubleToLongBits( this.dvalue );
- this.setHashCode( (int) (temp ^ (temp >>> 32)) );
+ if ( !isNull ) {
+ this.dvalue = extractor.getDoubleValue( null, value );
+ final long temp = Double.doubleToLongBits( this.dvalue );
+ this.setHashCode( (int) (temp ^ (temp >>> 32)) );
+ } else {
+ this.setHashCode( 0 );
+ }
} else {
- this.ovalue = extractor.getValue( null, value );
this.type = OBJECT;
- this.setHashCode( this.ovalue != null ? this.ovalue.hashCode() : 0 );
+ if ( !isNull ) {
+ this.ovalue = extractor.getValue( null, value );
+ this.setHashCode( this.ovalue != null ? this.ovalue.hashCode() : 0 );
+ } else {
+ this.setHashCode( 0 );
+ }
}
}
public void setValue(final int index,
final FieldValue value) {
this.index = index;
+
+ this.isNull = value.isNull();
+
if ( value.isBooleanField() ) {
- this.bvalue = value.getBooleanValue();
this.type = BOOL;
- this.setHashCode( this.bvalue ? 1231 : 1237 );
+ if ( !isNull ) {
+ this.bvalue = value.getBooleanValue();
+ this.setHashCode( this.bvalue ? 1231 : 1237 );
+ } else {
+ this.setHashCode( 0 );
+ }
} else if ( value.isIntegerNumberField() ) {
- this.lvalue = value.getLongValue();
this.type = LONG;
- this.setHashCode( (int) (this.lvalue ^ (this.lvalue >>> 32)) );
+ if ( !isNull ) {
+ this.lvalue = value.getLongValue();
+ this.setHashCode( (int) (this.lvalue ^ (this.lvalue >>> 32)) );
+ } else {
+ this.setHashCode( 0 );
+ }
} else if ( value.isFloatNumberField() ) {
- this.dvalue = value.getDoubleValue();
this.type = DOUBLE;
- final long temp = Double.doubleToLongBits( this.dvalue );
- this.setHashCode( (int) (temp ^ (temp >>> 32)) );
+ if ( !isNull ) {
+ this.dvalue = value.getDoubleValue();
+ final long temp = Double.doubleToLongBits( this.dvalue );
+ this.setHashCode( (int) (temp ^ (temp >>> 32)) );
+ } else {
+ this.setHashCode( 0 );
+ }
} else {
- this.ovalue = value.getValue();
this.type = OBJECT;
- this.setHashCode( this.ovalue != null ? this.ovalue.hashCode() : 0 );
+ if ( !isNull ) {
+ this.ovalue = value.getValue();
+ this.setHashCode( this.ovalue != null ? this.ovalue.hashCode() : 0 );
+ } else {
+ this.setHashCode( 0 );
+ }
}
}
@@ -598,6 +638,10 @@
public boolean equals(final Object object) {
final HashKey other = (HashKey) object;
+
+ if ( this.isNull ) {
+ return ( other.isNull );
+ }
switch ( this.type ) {
case BOOL :
More information about the jboss-svn-commits
mailing list