From a28709aabca96f19023370dd072cb3dc131e0e99 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Thu, 9 Aug 2007 15:50:21 +0000 Subject: Handle null value when converting String to Character. --- .../carbonado/repo/jdbc/JDBCStorableGenerator.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src') diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java index a1d3026..2f1c35c 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java @@ -1930,10 +1930,31 @@ class JDBCStorableGenerator { propertyType.toPrimitiveType() == TypeDesc.CHAR) { // Special case for converting String to character. + + Label charWasNull = null; + if (property.isNullable()) { + charWasNull = b.createLabel(); + LocalVariable temp = b.createLocalVariable(null, resultSetType); + b.storeLocal(temp); + b.loadLocal(temp); + b.ifNullBranch(charWasNull, true); + b.loadLocal(temp); + } + b.loadConstant(0); b.invokeVirtual(String.class.getName(), "charAt", TypeDesc.CHAR, new TypeDesc[] {TypeDesc.INT}); b.convert(TypeDesc.CHAR, propertyType); + + if (charWasNull != null) { + Label skipNull = b.createLabel(); + b.branch(skipNull); + + charWasNull.setLocation(); + b.loadNull(); + + skipNull.setLocation(); + } } else { b.convert(resultSetType, propertyType); } -- cgit v1.2.3