summaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java36
1 files changed, 36 insertions, 0 deletions
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;
}