summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--RELEASE-NOTES.txt2
-rw-r--r--src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java36
2 files changed, 38 insertions, 0 deletions
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 7fbc6a1..423b3ca 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -5,6 +5,8 @@ Carbonado change history
-------------------------------
- Removed call to get index metadata in JDBC repository. Oracle bug causes a
table analyze to run.
+- When a property evolves from a boxed primitive to an unboxed primitive, null
+ is converted to zero or false instead of throwing a NullPointerException.
1.1-BETA6 to 1.1-BETA7
-------------------------------
diff --git a/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java b/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java
index 2cd0807..76622b7 100644
--- a/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java
+++ b/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java
@@ -1840,6 +1840,7 @@ public class GenericEncodingStrategy<S extends Storable> {
if (prop.getType() == type.toClass()) {
break doDrop;
}
+
// Types differ, but if primitive types, perform conversion.
TypeDesc primType = type.toPrimitiveType();
if (primType != null) {
@@ -1847,7 +1848,42 @@ public class GenericEncodingStrategy<S extends Storable> {
TypeDesc primPropType = propType.toPrimitiveType();
if (primPropType != null) {
// Apply conversion and store property.
+
+ Label convertLabel = a.createLabel();
+ Label convertedLabel = a.createLabel();
+
+ if (!type.isPrimitive() && propType.isPrimitive()) {
+ // Might attempt to unbox null, which
+ // throws NullPointerException. Instead,
+ // convert null to zero or false.
+
+ a.dup();
+ a.ifNullBranch(convertLabel, false);
+ a.pop(); // pop null off stack
+
+ switch (propType.getTypeCode()) {
+ default:
+ a.loadConstant(0);
+ break;
+ case TypeDesc.LONG_CODE:
+ a.loadConstant(0L);
+ break;
+ case TypeDesc.FLOAT_CODE:
+ a.loadConstant(0.0f);
+ break;
+ case TypeDesc.DOUBLE_CODE:
+ a.loadConstant(0.0d);
+ break;
+ }
+
+ a.branch(convertedLabel);
+ }
+
+ convertLabel.setLocation();
a.convert(type, propType);
+
+ convertedLabel.setLocation();
+
type = propType;
break doDrop;
}