avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tazan007 <tazan...@gmail.com>
Subject Re: Null pointer error with ReflectData.getProtocol
Date Fri, 31 Jul 2009 21:33:36 GMT
Hi Doug, it seems the getSchema method is calling getPackage().getName() on
for example the java String class and that is what's failing.  I am
providing a package for my class.

The following generates a protocol without errors:

public class HelloWorld {
    public class MyString
    {
    }
    public void hello(MyString name)
    {
        System.out.println("test");
    }
}

But if I add the following field, it fails with the same error:

public class HelloWorld {
    public class MyString
    {
*        public String string;*
    }
    public void hello(MyString name)
    {
        System.out.println("test");
    }
}

Exception in thread "main" java.lang.NullPointerException
    at
org.apache.avro.reflect.ReflectData.createSchema(ReflectData.java:153)
    at
org.apache.avro.reflect.ReflectData.createSchema(ReflectData.java:183)
    at
org.apache.avro.reflect.ReflectData.createSchema(ReflectData.java:183)
    at org.apache.avro.reflect.ReflectData.getMessage(ReflectData.java:228)
    at org.apache.avro.reflect.ReflectData.getProtocol(ReflectData.java:204)

The following seems to fix it:

--- a/trunk/src/java/org/apache/avro/reflect/ReflectData.java
+++ b/trunk/src/java/org/apache/avro/reflect/ReflectData.java
@@ -123,6 +123,8 @@ public class ReflectData {
                                      Map<String,Schema> names) {
     if (type == Utf8.class)
       return Schema.create(Type.STRING);
+    else if (type == String.class)
+      return Schema.create(Type.STRING);
     else if (type == ByteBuffer.class)
       return Schema.create(Type.BYTES);
     else if ((type == Integer.class) || (type == Integer.TYPE))


Thanks,
Hiral

On Fri, Jul 31, 2009 at 1:38 PM, Moderator <cutting@apache.org> wrote:

> tazan007 wrote:
>
>> Exception in thread "main" java.lang.NullPointerException
>>    at
>> org.apache.avro.reflect.ReflectData.createSchema(ReflectData.java:153)
>>
>
> In the 1.0.0 source, ReflectData.java:153 is:
>
>  String space = c.getPackage().getName();
>
> So it seem that if you don't declare a package the package of a class is
> null, and Avro's reflect code does not check for that.  As a workaround
> you can put your class into a package.
>
> I've created a bug report to track this:
>
>  https://issues.apache.org/jira/browse/AVRO-86
>
> Doug
>
>

Mime
View raw message