]> source.dussan.org Git - jackcess.git/commitdiff
Fix NullPointerException in RowImpl.toString when value is null.
authorJames Ahlborn <jtahlborn@yahoo.com>
Wed, 22 Jan 2014 02:49:14 +0000 (02:49 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Wed, 22 Jan 2014 02:49:14 +0000 (02:49 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@844 f203690c-595d-4dc9-a70b-905162fa7fd2

src/changes/changes.xml
src/main/java/com/healthmarketscience/jackcess/impl/CustomToStringStyle.java
src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java

index 40c067abcb8e584085d30d5a740eba27cf824184..ca8ed975ad53c9853c2da59d61531b5a9d8a8e8f 100644 (file)
@@ -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
index 437f176889f16847b3444646f13d78f4caddf17a..f4772411dd200c79b53a1bb8b46c5f9cf6c2fda4 100644 (file)
@@ -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(") ");
index 5d6746352a3fdbfcc8d2dcafaa4119d1f74768c8..4f2d2c7f387e4c0b5b05d5b4d39cfa435b016404 100644 (file)
@@ -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) {