You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by cu...@apache.org on 2010/08/25 19:43:12 UTC
svn commit: r989252 - in /avro/trunk: CHANGES.txt
lang/java/src/java/org/apache/avro/reflect/ReflectData.java
lang/java/src/test/java/NoPackage.java
lang/java/src/test/java/org/apache/avro/TestReflect.java
Author: cutting
Date: Wed Aug 25 17:43:11 2010
New Revision: 989252
URL: http://svn.apache.org/viewvc?rev=989252&view=rev
Log:
AVRO-86. Java: Fix NullPointerException when reflect API infers schema for a class without a package.
Added:
avro/trunk/lang/java/src/test/java/NoPackage.java
Modified:
avro/trunk/CHANGES.txt
avro/trunk/lang/java/src/java/org/apache/avro/reflect/ReflectData.java
avro/trunk/lang/java/src/test/java/org/apache/avro/TestReflect.java
Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=989252&r1=989251&r2=989252&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Wed Aug 25 17:43:11 2010
@@ -178,6 +178,9 @@ Avro 1.4.0 (unreleased)
AVRO-541. Java: Fix sporadic corruption when appending a
compressed file to an uncompressed file. (scottcarey via cutting)
+ AVRO-86. Java: Fix NullPointerException when reflect API infers
+ schema for a class without a package. (cutting)
+
Avro 1.3.3 (7 June 2010)
IMPROVEMENTS
Modified: avro/trunk/lang/java/src/java/org/apache/avro/reflect/ReflectData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/java/org/apache/avro/reflect/ReflectData.java?rev=989252&r1=989251&r2=989252&view=diff
==============================================================================
--- avro/trunk/lang/java/src/java/org/apache/avro/reflect/ReflectData.java (original)
+++ avro/trunk/lang/java/src/java/org/apache/avro/reflect/ReflectData.java Wed Aug 25 17:43:11 2010
@@ -245,7 +245,7 @@ public class ReflectData extends Specifi
Schema schema = names.get(fullName);
if (schema == null) {
String name = c.getSimpleName();
- String space = c.getPackage().getName();
+ String space = c.getPackage() == null ? "" : c.getPackage().getName();
if (c.getEnclosingClass() != null) // nested class
space = c.getEnclosingClass().getName() + "$";
Union union = c.getAnnotation(Union.class);
@@ -321,7 +321,8 @@ public class ReflectData extends Specifi
Map<String,Field> fields = new LinkedHashMap<String,Field>();
Class c = recordClass;
do {
- if (c.getPackage().getName().startsWith("java."))
+ if (c.getPackage() != null
+ && c.getPackage().getName().startsWith("java."))
break; // skip java built-in classes
for (Field field : c.getDeclaredFields())
if ((field.getModifiers() & (Modifier.TRANSIENT|Modifier.STATIC)) == 0)
@@ -348,7 +349,8 @@ public class ReflectData extends Specifi
@Override
public Protocol getProtocol(Class iface) {
Protocol protocol =
- new Protocol(iface.getSimpleName(), iface.getPackage().getName());
+ new Protocol(iface.getSimpleName(),
+ iface.getPackage()==null?"":iface.getPackage().getName());
Map<String,Schema> names = new LinkedHashMap<String,Schema>();
Map<String,Message> messages = protocol.getMessages();
for (Method method : iface.getMethods())
Added: avro/trunk/lang/java/src/test/java/NoPackage.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/test/java/NoPackage.java?rev=989252&view=auto
==============================================================================
--- avro/trunk/lang/java/src/test/java/NoPackage.java (added)
+++ avro/trunk/lang/java/src/test/java/NoPackage.java Wed Aug 25 17:43:11 2010
@@ -0,0 +1,21 @@
+/**
+ * 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.
+ */
+
+/** I am a class without a package. */
+public interface NoPackage {
+}
Modified: avro/trunk/lang/java/src/test/java/org/apache/avro/TestReflect.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/test/java/org/apache/avro/TestReflect.java?rev=989252&r1=989251&r2=989252&view=diff
==============================================================================
--- avro/trunk/lang/java/src/test/java/org/apache/avro/TestReflect.java (original)
+++ avro/trunk/lang/java/src/test/java/org/apache/avro/TestReflect.java Wed Aug 25 17:43:11 2010
@@ -43,6 +43,7 @@ import org.apache.avro.reflect.ReflectDa
import org.apache.avro.reflect.Stringable;
import org.apache.avro.reflect.Nullable;
import org.apache.avro.reflect.Union;
+
import org.junit.Test;
public class TestReflect {
@@ -511,5 +512,14 @@ public class TestReflect {
ReflectData.get().getProtocol(P3.class);
}
+ @Test
+ public void testNoPackageSchema() throws Exception {
+ ReflectData.get().getSchema(Class.forName("NoPackage"));
+ }
+
+ @Test
+ public void testNoPackageProtocol() throws Exception {
+ ReflectData.get().getProtocol(Class.forName("NoPackage"));
+ }
}