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

Builder.build fails when enum has a default value

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • java
    • None

    Description

      I would expect this schema to allow building an Avro Issue without providing a value for severity but it fails:

      {
        "protocol" : "Protocol",
        "namespace" : "com.namespace",
        "types" : [ {
          "type" : "record",
          "name" : "Issue",
          "fields" : [ {
            "name" : "id",
            "type" : "string"
          }, {
            "name" : "severity",
            "type" : {
              "type" : "enum",
              "name" : "Severity",
              "symbols" : [ "Unknown", "Mild", "Moderate", "Severe" ],
              "default" : "Unknown"
            }
          } ]
        } ],
        "messages" : { }
      }
      
      Issue.newBuilder().setId("someId").build();
      

      Error:

      Field severity type:ENUM pos:4 not set and has no default value
      Path in schema: --> severity
      	at org.apache.avro.generic.GenericData.getDefaultValue(GenericData.java:1173)
      	at org.apache.avro.data.RecordBuilderBase.defaultValue(RecordBuilderBase.java:142)
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            safetytrick Michael Nielson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: