Avro
  1. Avro
  2. AVRO-1020

Builder API fails to substitute default values for enum types

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6.1
    • Fix Version/s: 1.6.2
    • Component/s: java
    • Labels:
      None

      Description

      If a schema has an enum type with a default value, and the Builder API is used to automatically substitute the default value on build(), a ClassCastException is thrown. The reason is that the default value resolves to a GenericData.EnumSymbol. The specific builder then attempts to cast this value to the corresponding Java enum type, which fails. Here is an example stack trace:

      org.apache.avro.AvroRuntimeException: java.lang.ClassCastException: org.apache.avro.generic.GenericData$EnumSymbol cannot be cast to org.apache.avro.ipc.specific.PrivacyType
      	at org.apache.avro.ipc.specific.Person$Builder.build(Person.java:410)
      	at org.apache.avro.specific.TestSpecificRecordBuilder.testSpecificBuilder(TestSpecificRecordBuilder.java:51)
      Caused by: java.lang.ClassCastException: org.apache.avro.generic.GenericData$EnumSymbol cannot be cast to org.apache.avro.ipc.specific.PrivacyType
      	at org.apache.avro.ipc.specific.Person$Builder.build(Person.java:407)
      	... 24 more
      
      1. AVRO-1020.patch
        4 kB
        Doug Cutting
      2. AVRO-1020.bug.patch
        0.6 kB
        James Baldassari

        Activity

        Hide
        James Baldassari added a comment -

        Here's a patch that exercises the bug. After applying this patch, TestSpecificRecordBuilder#testSpecificBuilder() fails.

        Show
        James Baldassari added a comment - Here's a patch that exercises the bug. After applying this patch, TestSpecificRecordBuilder#testSpecificBuilder() fails.
        Hide
        Doug Cutting added a comment -

        The problem is that RecordBuilderBase is hardwired to use GenericDatumReader.

        Here's a patch that fixes this by adding a createDatumReader() method to GenericData and its subclasses that returns the appropriate datum reader.

        Show
        Doug Cutting added a comment - The problem is that RecordBuilderBase is hardwired to use GenericDatumReader. Here's a patch that fixes this by adding a createDatumReader() method to GenericData and its subclasses that returns the appropriate datum reader.
        Hide
        Scott Carey added a comment -

        +1 Looks good, tests pass.

        Show
        Scott Carey added a comment - +1 Looks good, tests pass.
        Hide
        Doug Cutting added a comment -

        I committed this.

        Show
        Doug Cutting added a comment - I committed this.

          People

          • Assignee:
            Doug Cutting
            Reporter:
            James Baldassari
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development