avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r900628 - in /hadoop/avro/trunk: CHANGES.txt lang/java/src/java/org/apache/avro/generic/GenericData.java lang/java/src/test/java/org/apache/avro/generic/TestGenericData.java
Date Tue, 19 Jan 2010 00:49:33 GMT
Author: cutting
Date: Tue Jan 19 00:49:33 2010
New Revision: 900628

URL: http://svn.apache.org/viewvc?rev=900628&view=rev
Log:
AVRO-336. Check that appropriate schemas are passed to GenericRecord#Array and #Record.

Modified:
    hadoop/avro/trunk/CHANGES.txt
    hadoop/avro/trunk/lang/java/src/java/org/apache/avro/generic/GenericData.java
    hadoop/avro/trunk/lang/java/src/test/java/org/apache/avro/generic/TestGenericData.java

Modified: hadoop/avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=900628&r1=900627&r2=900628&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Tue Jan 19 00:49:33 2010
@@ -224,6 +224,9 @@
     AVRO-198. Fix specification of protocol name, also clarify which
     properties are required.  (cutting)
 
+    AVRO-336. Check that appropriate schemas are passed to
+    GenericData#Record and #Array.  (cutting)
+
   OPTIMIZATIONS
 
     AVRO-172. More efficient schema processing (massie)

Modified: hadoop/avro/trunk/lang/java/src/java/org/apache/avro/generic/GenericData.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/java/src/java/org/apache/avro/generic/GenericData.java?rev=900628&r1=900627&r2=900628&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/java/src/java/org/apache/avro/generic/GenericData.java (original)
+++ hadoop/avro/trunk/lang/java/src/java/org/apache/avro/generic/GenericData.java Tue Jan
19 00:49:33 2010
@@ -45,7 +45,8 @@
     private final Schema schema;
     private final Object[] values;
     public Record(Schema schema) {
-      if (schema == null) throw new NullPointerException();
+      if (schema == null || !Type.RECORD.equals(schema.getType()))
+        throw new AvroRuntimeException("Not a record schema: "+schema);
       this.schema = schema;
       this.values = new Object[schema.getFields().size()];
     }
@@ -86,7 +87,8 @@
     private int size;
     private Object[] elements = EMPTY;
     public Array(int capacity, Schema schema) {
-      if (schema == null) throw new NullPointerException();
+      if (schema == null || !Type.ARRAY.equals(schema.getType()))
+        throw new AvroRuntimeException("Not an array schema: "+schema);
       this.schema = schema;
       if (capacity != 0)
         elements = new Object[capacity];

Modified: hadoop/avro/trunk/lang/java/src/test/java/org/apache/avro/generic/TestGenericData.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/java/src/test/java/org/apache/avro/generic/TestGenericData.java?rev=900628&r1=900627&r2=900628&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/java/src/test/java/org/apache/avro/generic/TestGenericData.java
(original)
+++ hadoop/avro/trunk/lang/java/src/test/java/org/apache/avro/generic/TestGenericData.java
Tue Jan 19 00:49:33 2010
@@ -19,18 +19,31 @@
 
 import static org.junit.Assert.*;
 
+import org.apache.avro.Schema;
+import org.apache.avro.AvroRuntimeException;
+
 import org.junit.Test;
 
 public class TestGenericData {
   
-  @Test(expected=NullPointerException.class)
+  @Test(expected=AvroRuntimeException.class)
     public void testrecordConstructorNullSchema() throws Exception {
     new GenericData.Record(null);
   }
     
-  @Test(expected=NullPointerException.class)
+  @Test(expected=AvroRuntimeException.class)
+    public void testrecordConstructorWrongSchema() throws Exception {
+    new GenericData.Record(Schema.create(Schema.Type.INT));
+  }
+
+  @Test(expected=AvroRuntimeException.class)
     public void testArrayConstructorNullSchema() throws Exception {
     new GenericData.Array<Object>(1, null);
   }
     
+  @Test(expected=AvroRuntimeException.class)
+    public void testArrayConstructorWrongSchema() throws Exception {
+    new GenericData.Array<Object>(1, Schema.create(Schema.Type.INT));
+  }
+
 }



Mime
View raw message