GitHub user samschlegel opened a pull request:

    https://github.com/apache/avro/pull/237

    [AVRO-2058] ReflectData#isNonStringMap returns true for Utf8 keys

    https://issues.apache.org/jira/browse/AVRO-2058
    
    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:
    
    ```java
      @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));
      }
    ```


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/samschlegel/avro master

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/avro/pull/237.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #237
    
----
commit 8852da40e7a0ee58d9b027173a4972e7e71b432d
Author: Sam Schlegel <[email protected]>
Date:   2017-07-27T02:20:51Z

    Add failing test

commit 15fbb40944dc15a37569aa6a3d2e93db0e085af0
Author: Sam Schlegel <[email protected]>
Date:   2017-07-27T02:23:21Z

    Add Stringable annotation

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to