Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-1592

Java keyword as an enum constant in Avro schema file causes deserialization to fail.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7.7
    • 1.8.0
    • java
    • None
    • CentOS, Java 1.7

    Description

      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 exception:

      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.

      Attachments

        1. fix_java_keyword_enums.patch
          2 kB
          Lukas Steiblys
        2. avrobug.tar.gz
          2 kB
          Lukas Steiblys
        3. AVRO-1592.patch
          5 kB
          Doug Cutting

        Activity

          People

            imbusy Lukas Steiblys
            imbusy Lukas Steiblys
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: