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

RecordBuilderBase.validate doesn't check nullability of composite types

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.9.0, 1.8.2
    • Fix Version/s: None
    • Component/s: java
    • Labels:
      None

      Description

      Builder classes generated from record.vm make use of RecordBuilderBase.validate in every setter to ensure that the passed value (primitive or composite) is compatible with the nullability of the corresponding Avro schema type.  The problem is the validation doesn't extend to composite types, namely Maps and Arrays.  This breaks the invariant that any record constructed via Builder is well-defined (i.e., can be serialized).

      E.g., field of type array<string> would yield the following setter,

      x.y.z.Builder setXXX(java.util.List<java.lang.String> value)

      Thus, a collection with a null element will result in a record which breaks serialization, e.g.,

      datumWriter.write(builder.setXXX(Collections.singletonList(null)).build())

      will throw NPE.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                srosenberg Stan Rosenberg
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: