Return-Path: X-Original-To: apmail-avro-dev-archive@www.apache.org Delivered-To: apmail-avro-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E86AA17D9A for ; Wed, 29 Oct 2014 21:06:34 +0000 (UTC) Received: (qmail 34708 invoked by uid 500); 29 Oct 2014 21:06:34 -0000 Delivered-To: apmail-avro-dev-archive@avro.apache.org Received: (qmail 34640 invoked by uid 500); 29 Oct 2014 21:06:34 -0000 Mailing-List: contact dev-help@avro.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@avro.apache.org Delivered-To: mailing list dev@avro.apache.org Received: (qmail 34628 invoked by uid 99); 29 Oct 2014 21:06:34 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Oct 2014 21:06:34 +0000 Date: Wed, 29 Oct 2014 21:06:34 +0000 (UTC) From: "Doug Cutting (JIRA)" To: dev@avro.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (AVRO-1592) Java keyword as an enum constant in Avro schema file causes deserialization to fail. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/AVRO-1592?page=3Dcom.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 repea= ting them. A small bit of logic from SpecificCompiler#mangle() is still re= peated, 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 deserializati= on 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_en= ums.patch > > > The schema {"type": "enum", "name": "ButtonTypeID", "symbols": ["default"= , "keyboard"]} generates the following class: > =20 > public final class ButtonTypeID extends java.lang.Enum { > 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 {}; > } > =20 > (this is what =E2=80=9Cjavap ButtonTypeID.class=E2=80=9D produces) > =20 > When I try to read my data that has the =E2=80=9Cdefault=E2=80=9D value f= or ButtonTypeID, I get the exception: > java.lang.IllegalArgumentException: No enum constant ButtonTypeID.default > =09at java.lang.Enum.valueOf(Enum.java:236) > =09at org.apache.avro.specific.SpecificData.createEnum(SpecificData.java:= 106) > =09at org.apache.avro.generic.GenericDatumReader.createEnum(GenericDatumR= eader.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 (v6.3.4#6332)