avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r897352 - in /hadoop/avro/trunk: CHANGES.txt src/java/org/apache/avro/generic/GenericData.java src/test/java/org/apache/avro/generic/ src/test/java/org/apache/avro/generic/TestGenericData.java
Date Sat, 09 Jan 2010 00:03:46 GMT
Author: cutting
Date: Sat Jan  9 00:03:46 2010
New Revision: 897352

URL: http://svn.apache.org/viewvc?rev=897352&view=rev
Log:
AVRO-259. Add null schema check in GenericData.Record and GenericData.Array constructors.
 Contributed by Kevin Oliver.

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

Modified: hadoop/avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=897352&r1=897351&r2=897352&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Sat Jan  9 00:03:46 2010
@@ -182,6 +182,9 @@
     AVRO-75. Clarify that missing values with no default values cause
     errors, and fix Java implementation.  (cutting)
 
+    AVRO-259. Add null schema check in GenericData.Record and
+    GenericData.Array construtors. (Kevin Oliver via cutting)
+
   OPTIMIZATIONS
 
     AVRO-172. More efficient schema processing (massie)

Modified: hadoop/avro/trunk/src/java/org/apache/avro/generic/GenericData.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/generic/GenericData.java?rev=897352&r1=897351&r2=897352&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/generic/GenericData.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/generic/GenericData.java Sat Jan  9 00:03:46
2010
@@ -45,6 +45,7 @@
     private final Schema schema;
     private final Object[] values;
     public Record(Schema schema) {
+      if (schema == null) throw new NullPointerException();
       this.schema = schema;
       this.values = new Object[schema.getFields().size()];
     }
@@ -85,6 +86,7 @@
     private int size;
     private Object[] elements = EMPTY;
     public Array(int capacity, Schema schema) {
+      if (schema == null) throw new NullPointerException();
       this.schema = schema;
       if (capacity != 0)
         elements = new Object[capacity];
@@ -120,7 +122,7 @@
       Array that = (Array)o;
       if (!schema.equals(that.schema))
         return false;                             // not the same schema
-      return this.compareTo((Array)that) == 0;
+      return this.compareTo(that) == 0;
     }
     public int compareTo(Array<T> that) {
       return GenericData.get().compare(this, that, this.getSchema());
@@ -403,7 +405,6 @@
 
   /** Compute a hash code according to a schema, consistent with {@link
    * #compare(Object,Object,Schema)}. */
-  @SuppressWarnings(value="unchecked")
   public int hashCode(Object o, Schema s) {
     int hashCode = 1;
     switch (s.getType()) {

Added: hadoop/avro/trunk/src/test/java/org/apache/avro/generic/TestGenericData.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/test/java/org/apache/avro/generic/TestGenericData.java?rev=897352&view=auto
==============================================================================
--- hadoop/avro/trunk/src/test/java/org/apache/avro/generic/TestGenericData.java (added)
+++ hadoop/avro/trunk/src/test/java/org/apache/avro/generic/TestGenericData.java Sat Jan 
9 00:03:46 2010
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.avro.generic;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class TestGenericData {
+  
+  @Test(expected=NullPointerException.class)
+    public void testrecordConstructorNullSchema() throws Exception {
+    new GenericData.Record(null);
+  }
+    
+  @Test(expected=NullPointerException.class)
+    public void testArrayConstructorNullSchema() throws Exception {
+    new GenericData.Array<Object>(1, null);
+  }
+    
+}



Mime
View raw message