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

If a default value is set, Avro allows null values in non-nullable fields.

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.8.1
    • Fix Version/s: None
    • Component/s: java
    • Labels:
      None

      Description

      With an avro schema like

      {
        "name": "myfield",
        "type": "string",
        "default": ""
      }
      

      the following code should throw an exception

      MyObject myObject = MyObject.newBuilder().setMyfield(null).build();
      

      But instead the value of myfield is set to null, which causes an exception later when serializing myObject, because null is not a valid value for myfield.

      I believe in this case setMyfield(null) should throw an exception, independent of the value of default.
      See also
      https://stackoverflow.com/questions/38509279/generated-avro-builder-set-null-doesnt-overwrite-with-default

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                asmaier Andreas Maier
              • Votes:
                1 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated: