[ 
https://issues.apache.org/jira/browse/AVRO-1544?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Matthew Hayes updated AVRO-1544:
--------------------------------

    Attachment: AVRO-1544.patch

Attaching patch with null check and unit test exposing the issue.

Testing done: "mvn test"

To run the single test: "mvn -Dtest=TestGenericData#testValidateNullableEnum 
test"

Note that this is somewhat related to AVRO-997.  I see that the latest patch 
there includes this change:

{code}
     case ENUM:
+      if (!isEnum(datum)) return false;
       return schema.getEnumSymbols().contains(datum.toString());
{code}

I believe this change would probably address this issue as well.  However, I 
think this particular change may not be backwards compatible.  Currently you 
can pass in strings as I do in the unit test to validate and it works.

> Union of enum and null can result in NPE on validate if null is not first
> -------------------------------------------------------------------------
>
>                 Key: AVRO-1544
>                 URL: https://issues.apache.org/jira/browse/AVRO-1544
>             Project: Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.7.6
>            Reporter: Matthew Hayes
>         Attachments: AVRO-1544.patch
>
>
> The ENUM case in validate is missing a null check for datum:
> {code}
>     case ENUM:
>       return schema.getEnumSymbols().contains(datum.toString());
> {code}
> This leads to a surprising error where a NPE is thrown for a union of enum 
> and null when the enum is first in the union.  If null is first it works.  
> The fix is a simple.  I'm creating a patch that adds the fix and a unit test 
> for this case.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to