diff options
-rw-r--r-- | src/changes/changes.xml | 5 | ||||
-rw-r--r-- | src/main/java/com/healthmarketscience/jackcess/impl/CustomToStringStyle.java | 17 | ||||
-rw-r--r-- | src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java | 8 |
3 files changed, 26 insertions, 4 deletions
diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 40c067a..ca8ed97 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -4,6 +4,11 @@ <author email="javajedi@users.sf.net">Tim McCune</author> </properties> <body> + <release version="2.0.3" date="TBD"> + <action dev="jahlborn" type="fix"> + Fix NullPointerException in RowImpl.toString() when value is null. + </action> + </release> <release version="2.0.2" date="2013-11-30"> <action dev="jahlborn" type="fix" system="SourceForge2" issue="99"> Rework row add/update so that constraint violations do not leave diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/CustomToStringStyle.java b/src/main/java/com/healthmarketscience/jackcess/impl/CustomToStringStyle.java index 437f176..f477241 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/CustomToStringStyle.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/CustomToStringStyle.java @@ -119,11 +119,11 @@ public class CustomToStringStyle extends StandardToStringStyle if(isFieldSeparatorAtStart()) { appendFieldSeparator(sb); } - appendInternal(sb, fieldName, iter.next(), true); + appendValueDetail(sb, fieldName, iter.next()); } while(iter.hasNext()) { sb.append(getArraySeparator()); - appendInternal(sb, fieldName, iter.next(), true); + appendValueDetail(sb, fieldName, iter.next()); } // indent entire list contents another level @@ -151,13 +151,13 @@ public class CustomToStringStyle extends StandardToStringStyle } Map.Entry<?,?> e = iter.next(); sb.append(e.getKey()).append("="); - appendInternal(sb, fieldName, e.getValue(), true); + appendValueDetail(sb, fieldName, e.getValue()); } while(iter.hasNext()) { sb.append(getArraySeparator()); Map.Entry<?,?> e = iter.next(); sb.append(e.getKey()).append("="); - appendInternal(sb, fieldName, e.getValue(), true); + appendValueDetail(sb, fieldName, e.getValue()); } // indent entire map contents another level @@ -175,6 +175,15 @@ public class CustomToStringStyle extends StandardToStringStyle appendDetail(buffer, PageChannel.wrap(array)); } + private void appendValueDetail(StringBuffer buffer, String fieldName, + Object value) { + if (value == null) { + appendNullText(buffer, fieldName); + } else { + appendInternal(buffer, fieldName, value, true); + } + } + private static void appendDetail(StringBuffer buffer, ByteBuffer bb) { int len = bb.remaining(); buffer.append("(").append(len).append(") "); diff --git a/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java b/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java index 5d67463..4f2d2c7 100644 --- a/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -1440,6 +1440,14 @@ public class DatabaseTest extends TestCase } } + public void testToString() + { + RowImpl row = new RowImpl(new RowIdImpl(1, 1)); + row.put("id", 37); + row.put("data", null); + assertEquals("Row[1:1][{id=37,data=<null>}]", row.toString()); + } + private void checkRawValue(String expected, Object val) { if(expected != null) { |