Repository: avro Updated Branches: refs/heads/branch-1.8 ea784c8b0 -> fb821095a
AVRO-1401: @Nullable does not work with byte[] This closes #229 (cherry picked from commit c04a17c86078431d0ae33a3045520e3ec9d9787d) Project: http://git-wip-us.apache.org/repos/asf/avro/repo Commit: http://git-wip-us.apache.org/repos/asf/avro/commit/fb821095 Tree: http://git-wip-us.apache.org/repos/asf/avro/tree/fb821095 Diff: http://git-wip-us.apache.org/repos/asf/avro/diff/fb821095 Branch: refs/heads/branch-1.8 Commit: fb821095aea715a339ad9b1b7738718927b236d2 Parents: ea784c8 Author: Nandor Kollar <[email protected]> Authored: Fri Jun 9 00:44:37 2017 +0200 Committer: Gabor Szadovszky <[email protected]> Committed: Wed Jun 14 12:51:39 2017 +0200 ---------------------------------------------------------------------- CHANGES.txt | 12 +++++++++ .../org/apache/avro/reflect/ReflectData.java | 10 +++++--- .../org/apache/avro/reflect/TestReflect.java | 27 ++++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/avro/blob/fb821095/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 4c8b998..92a3e55 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,17 @@ Avro Change Log +Trunk (not yet released) + + NEW FEATURES + + OPTIMIZATIONS + + IMPROVEMENTS + + BUG FIXES + + AVRO-1401: @Nullable does not work with byte[] (Nandor Kollar via gabor) + Avro 1.8.2 (10 April 2017) INCOMPATIBLE CHANGES http://git-wip-us.apache.org/repos/asf/avro/blob/fb821095/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java ---------------------------------------------------------------------- diff --git a/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java b/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java index 6b6ae4e..60095ad 100644 --- a/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java +++ b/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java @@ -180,14 +180,18 @@ public class ReflectData extends SpecificData { } /** - * Returns true also for non-string-keyed maps, which are written as an array - * of key/value pair records. + * Returns true for arrays and false otherwise, with the following exceptions: + * <ul> + * <li><p>Returns true for non-string-keyed maps, which are written as an array of key/value pair records.</p></li> + * <li><p>Returns false for arrays of bytes, since those should be treated as byte data type instead.</p></li> + * </ul> */ @Override protected boolean isArray(Object datum) { if (datum == null) return false; + Class c = datum.getClass(); return (datum instanceof Collection) - || datum.getClass().isArray() + || (c.isArray() && c.getComponentType() != Byte.TYPE) || isNonStringMap(datum); } http://git-wip-us.apache.org/repos/asf/avro/blob/fb821095/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java ---------------------------------------------------------------------- diff --git a/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java b/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java index a281a06..8b23730 100644 --- a/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java +++ b/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java @@ -1048,4 +1048,31 @@ public class TestReflect { +"{\"name\":\"foo\",\"type\":\"int\",\"default\":1}]}"); } + public static class NullableBytesTest { + @Nullable + byte[] bytes; + + NullableBytesTest() { + } + + NullableBytesTest(byte[] bytes) { + this.bytes = bytes; + } + + @Override + public boolean equals(Object obj) { + return obj instanceof NullableBytesTest + && Arrays.equals(((NullableBytesTest) obj).bytes, this.bytes); + } + } + + @Test + public void testNullableByteArrayNotNullValue() throws Exception { + checkReadWrite(new NullableBytesTest("foo".getBytes())); + } + + @Test + public void testNullableByteArrayNullValue() throws Exception { + checkReadWrite(new NullableBytesTest()); + } }
