avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Doug Cutting (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (AVRO-1592) Java keyword as an enum constant in Avro schema file causes deserialization to fail.
Date Wed, 29 Oct 2014 21:06:34 GMT

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

Doug Cutting updated AVRO-1592:
    Attachment: AVRO-1592.patch

Here's an updated patch.

Changes are:
 - Move reserved words from SpecificCompiler to SpecificData to avoid repeating them.  A small
bit of logic from SpecificCompiler#mangle() is still repeated, but fixing that is harder.
 - In SpecificData#createEnum(), don't alter 'symbol' parameter until after super is called.
 - Add a test that fails without these changes but succeeds with them.

I'll commit this soon unless there are objections.

> Java keyword as an enum constant in Avro schema file causes deserialization to fail.
> ------------------------------------------------------------------------------------
>                 Key: AVRO-1592
>                 URL: https://issues.apache.org/jira/browse/AVRO-1592
>             Project: Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.7.7
>         Environment: CentOS, Java 1.7
>            Reporter: Lukas Steiblys
>             Fix For: 1.8.0
>         Attachments: AVRO-1592.patch, avrobug.tar.gz, fix_java_keyword_enums.patch
> The schema {"type": "enum", "name": "ButtonTypeID", "symbols": ["default", "keyboard"]}
generates the following class:
> public final class ButtonTypeID extends java.lang.Enum<ButtonTypeID> {
>   public static final ButtonTypeID default$;
>   public static final ButtonTypeID keyboard;
>   public static final org.apache.avro.Schema SCHEMA$;
>   public static ButtonTypeID[] values();
>   public static ButtonTypeID valueOf(java.lang.String);
>   public static org.apache.avro.Schema getClassSchema();
>   static {};
> }
> (this is what “javap ButtonTypeID.class” produces)
> When I try to read my data that has the “default” value for ButtonTypeID, I get the
> java.lang.IllegalArgumentException: No enum constant ButtonTypeID.default
> 	at java.lang.Enum.valueOf(Enum.java:236)
> 	at org.apache.avro.specific.SpecificData.createEnum(SpecificData.java:106)
> 	at org.apache.avro.generic.GenericDatumReader.createEnum(GenericDatumReader.java:205)...
> Since "default" is a keyword in java, the $ is appended to the constant, but that is
not taken into account when reading the data back, causing the ButtonTypeID.valueOf("default")
method to fail.

This message was sent by Atlassian JIRA

View raw message