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

ReflectData.AllowNull incorrectly handles primitive types.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Duplicate
    • 1.7.7
    • None
    • java
    • None

    Description

      When doing the following:

      private static class PoJo {
        private long id;
        private String name;
      }
      
      ReflectData.AllowNull.get().getSchema(PoJo.class);
      

      I'd expect a schema like this:

      {
        "type" : "record",
        "name" : "PoJo",
        "namespace" : "MyObject$",
        "fields" : [ {
          "name" : "id",
          "type" : "long",
        }, {
          "name" : "name",
          "type" : [ "null", "string" ],
          "default" : null
        } ]
      }
      

      But instead I get:

      {
        "type" : "record",
        "name" : "PoJo",
        "namespace" : "MyObject$",
        "fields" : [ {
          "name" : "id",
          "type" : [ "null", "long" ],
          "default" : null
        }, {
          "name" : "name",
          "type" : [ "null", "string" ],
          "default" : null
        } ]
      }
      

      This will later result in an NullPointerException when you try to deserialize bytes where id was null when it tries to convert the Long to a long.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              fwiffo Joey Echeverria
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: