From 0a2252bdda57afa5b953658a4f7ee80d7a4d69d4 Mon Sep 17 00:00:00 2001 From: Alejandro Abdelnur Date: Fri, 6 Jul 2012 22:27:13 +0000 Subject: [PATCH] HADOOP-8566. AvroReflectSerializer.accept(Class) throws a NPE if the class has no package (primitive types and arrays). (tucu) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1358454 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../io/serializer/avro/AvroReflectSerialization.java | 4 ++-- .../hadoop/io/serializer/avro/TestAvroSerialization.java | 7 +++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 9126d8fe9e..ece64bd296 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -313,6 +313,9 @@ Branch-2 ( Unreleased changes ) HADOOP-8563. don't package hadoop-pipes examples/bin (Colin Patrick McCabe via tgraves) + HADOOP-8566. AvroReflectSerializer.accept(Class) throws a NPE if the class has no + package (primitive types and arrays). (tucu) + BREAKDOWN OF HDFS-3042 SUBTASKS HADOOP-8220. ZKFailoverController doesn't handle failure to become active diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/serializer/avro/AvroReflectSerialization.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/serializer/avro/AvroReflectSerialization.java index 5636b597e3..cfbc60d104 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/serializer/avro/AvroReflectSerialization.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/serializer/avro/AvroReflectSerialization.java @@ -58,8 +58,8 @@ public synchronized boolean accept(Class c) { if (packages == null) { getPackages(); } - return AvroReflectSerializable.class.isAssignableFrom(c) || - packages.contains(c.getPackage().getName()); + return AvroReflectSerializable.class.isAssignableFrom(c) || + (c.getPackage() != null && packages.contains(c.getPackage().getName())); } private void getPackages() { diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/serializer/avro/TestAvroSerialization.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/serializer/avro/TestAvroSerialization.java index 08f2c40e9e..181419c137 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/serializer/avro/TestAvroSerialization.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/serializer/avro/TestAvroSerialization.java @@ -21,6 +21,7 @@ import junit.framework.TestCase; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.io.serializer.SerializationFactory; import org.apache.hadoop.io.serializer.SerializationTestUtil; public class TestAvroSerialization extends TestCase { @@ -43,6 +44,12 @@ public void testReflectPkg() throws Exception { assertEquals(before, after); } + public void testAcceptHandlingPrimitivesAndArrays() throws Exception { + SerializationFactory factory = new SerializationFactory(conf); + assertNull(factory.getSerializer(byte[].class)); + assertNull(factory.getSerializer(byte.class)); + } + public void testReflectInnerClass() throws Exception { InnerRecord before = new InnerRecord(); before.x = 10;