avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joey Echeverria (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (AVRO-1588) ReflectData.AllowNull incorrectly handles primitive types.
Date Wed, 17 Sep 2014 22:23:34 GMT

    [ https://issues.apache.org/jira/browse/AVRO-1588?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14138117#comment-14138117
] 

Joey Echeverria commented on AVRO-1588:
---------------------------------------

I think it should special case primitive fields to not be nullable. I view ReflectData.AllowNull
to be a short cut to adding {{@Nullable}} to the fields of my PoJo, or for cases where I don't
control the source of the PoJo. But I wouldn't expect it to produce a schema that isn't actually
compatible with my class. In particular, if I'm using ReflectData.AllowNull to extract a schema
and then use it to read data, I'd like to be able to check schema compatibility in advance
and get an error if the writer schema allows nulls for one of the fields that is a primitive
in my class. As it stands today, I won't get an error until I actually try to read the data
and the error I'll get is a NullPointerException.

> ReflectData.AllowNull incorrectly handles primitive types.
> ----------------------------------------------------------
>
>                 Key: AVRO-1588
>                 URL: https://issues.apache.org/jira/browse/AVRO-1588
>             Project: Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.7.7
>            Reporter: Joey Echeverria
>
> When doing the following:
> {code:java}
> private static class PoJo {
>   private long id;
>   private String name;
> }
> ReflectData.AllowNull.get().getSchema(PoJo.class);
> {code}
> I'd expect a schema like this:
> {code:javascript}
> {
>   "type" : "record",
>   "name" : "PoJo",
>   "namespace" : "MyObject$",
>   "fields" : [ {
>     "name" : "id",
>     "type" : "long",
>   }, {
>     "name" : "name",
>     "type" : [ "null", "string" ],
>     "default" : null
>   } ]
> }
> {code}
> But instead I get:
> {code:javascript}
> {
>   "type" : "record",
>   "name" : "PoJo",
>   "namespace" : "MyObject$",
>   "fields" : [ {
>     "name" : "id",
>     "type" : [ "null", "long" ],
>     "default" : null
>   }, {
>     "name" : "name",
>     "type" : [ "null", "string" ],
>     "default" : null
>   } ]
> }
> {code}
> This will later result in an NullPointerException when you try to deserialize bytes where
id was null when it tries to convert the Long to a long.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message