avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1087136 - in /avro/trunk: ./ lang/java/avro/src/main/java/org/apache/avro/reflect/ lang/java/avro/src/test/java/org/apache/avro/
Date Wed, 30 Mar 2011 23:36:21 GMT
Author: cutting
Date: Wed Mar 30 23:36:20 2011
New Revision: 1087136

URL: http://svn.apache.org/viewvc?rev=1087136&view=rev
Log:
AVRO-780. Java: Fix a NullPointerException with reflect data when a union contains an array
and null.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectDatumWriter.java
    avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestReflect.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1087136&r1=1087135&r2=1087136&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Wed Mar 30 23:36:20 2011
@@ -29,6 +29,9 @@ Avro 1.5.1 (unreleased)
 
     AVRO-786. Java: Fix equals() to work on objects containing maps. (cutting)
 
+    AVRO-780. Java: Fix a NullPointerException with reflect data when
+    a union contains an array and null. (cutting)
+
 Avro 1.5.0 (10 March 2011)
 
   INCOMPATIBLE CHANGES

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java?rev=1087136&r1=1087135&r2=1087136&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java (original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java Wed Mar
30 23:36:20 2011
@@ -106,6 +106,7 @@ public class ReflectData extends Specifi
 
   @Override
   protected boolean isArray(Object datum) {
+    if (datum == null) return false;
     return (datum instanceof Collection) || datum.getClass().isArray();
   }
 

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectDatumWriter.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectDatumWriter.java?rev=1087136&r1=1087135&r2=1087136&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectDatumWriter.java
(original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectDatumWriter.java
Wed Mar 30 23:36:20 2011
@@ -103,7 +103,7 @@ public class ReflectDatumWriter<T> exten
     } catch (NullPointerException e) {            // improve error message
       NullPointerException result =
         new NullPointerException("in "+schema.getFullName()+" "+e.getMessage());
-      result.initCause(e);
+      result.initCause(e.getCause() == null ? e : e.getCause());
       throw result;
     }
   }

Modified: avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestReflect.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestReflect.java?rev=1087136&r1=1087135&r2=1087136&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestReflect.java (original)
+++ avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestReflect.java Wed Mar 30 23:36:20
2011
@@ -550,6 +550,14 @@ public class TestReflect {
     checkBinary(schema, record);
   }
 
+  /** Test union of null and an array. */
+  @Test
+  public void testNullArray() throws Exception {
+    String json = "[{\"type\":\"array\", \"items\": \"long\"}, \"null\"]";
+    Schema schema = Schema.parse(json);
+    checkBinary(schema, null);
+  }
+
   public static void checkBinary(Schema schema, Object datum)
     throws IOException {
     ReflectDatumWriter<Object> writer = new ReflectDatumWriter<Object>(schema);



Mime
View raw message