You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Ryan Skraba (Jira)" <ji...@apache.org> on 2020/11/09 14:36:00 UTC

[jira] [Commented] (AVRO-2956) SpecificRecord decoding fails if Java keyword is used as record name

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

Ryan Skraba commented on AVRO-2956:
-----------------------------------

I can reproduce this in 1.10.0 and 1.9.2 – it looks like the code that [maps a record name to a known Java class|https://github.com/apache/avro/blob/2c7b9af7d5ba35afe9cf84eae3b273a6df0612b1/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java#L246] doesn't work for keywords.

The list of keywords is right there, so we could take it into account for records, package names, etc.   It looks like createEnum already does this for enum symbols for example.

As an example, AVRO-2757 was recently added in this code to correctly map a record name to a static inner class.

> SpecificRecord decoding fails if Java keyword is used as record name
> --------------------------------------------------------------------
>
>                 Key: AVRO-2956
>                 URL: https://issues.apache.org/jira/browse/AVRO-2956
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.10.0
>            Reporter: Richard Fussenegger
>            Priority: Major
>
> Someone created an Avro definition where the name of a record is {{case}}:
> {code:none}
> protocol Proto {
>     record case {
>         string value;
>     }
>     record Wrapper {
>         case inner;
>     }
> }
> {code}
> Code generation works and the generated Java code uses {{case$}} for the class name of the record. There is no problem in writing the Java code itself, however, decoding with a {{SpecificRecord.getDecoder()}} fails with a {{ClassCastException}}:
> {code:none}
> class org.apache.avro.generic.GenericData$Record cannot be cast to class case$ (org.apache.avro.generic.GenericData$Record and case$ are in unnamed module of loader 'app')
> java.lang.ClassCastException: class org.apache.avro.generic.GenericData$Record cannot be cast to class case$ (org.apache.avro.generic.GenericData$Record and case$ are in unnamed module of loader 'app')
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)