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

ReflectData#isNonStringMap returns true for Utf8 keys

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • 1.8.2
    • 1.9.0
    • java
    • None

    Description

      Since Utf8 does not have an Stringable notation, and is not in SpecificData#stringableClasses, ReflectData#isNonStringMap returns true. This also causes ReflectData#isArray to return true for maps with Utf8 keys, and thus GenericData#resolveUnion fails as well. This ultimately causes ReflectData#write to fail for schemas that contain a union that contains a map, where the data uses Utf8 for strings.

      This following test case reproduces the issue:

        @Test public void testUnionWithMapWithUtf8Keys() {
          Schema s = new Schema.Parser().parse
            ("[\"null\", {\"type\":\"map\",\"values\":\"float\"}]");
          GenericData data = ReflectData.get();
          HashMap<Utf8,Float> map = new HashMap<Utf8,Float>();
          map.put(new Utf8("foo"), 1.0f);
          assertEquals(1, data.resolveUnion(s, map));
        }
      

      Attachments

        1. AVRO-2058.patch
          2 kB
          Sam Schlegel

        Activity

          People

            SamSchlegel Sam Schlegel
            SamSchlegel Sam Schlegel
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: