You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by ga...@apache.org on 2017/06/14 09:42:21 UTC
avro git commit: AVRO-1401: @Nullable does not work with byte[]
Repository: avro
Updated Branches:
refs/heads/master 8336f7ece -> c04a17c86
AVRO-1401: @Nullable does not work with byte[]
This closes #229
Project: http://git-wip-us.apache.org/repos/asf/avro/repo
Commit: http://git-wip-us.apache.org/repos/asf/avro/commit/c04a17c8
Tree: http://git-wip-us.apache.org/repos/asf/avro/tree/c04a17c8
Diff: http://git-wip-us.apache.org/repos/asf/avro/diff/c04a17c8
Branch: refs/heads/master
Commit: c04a17c86078431d0ae33a3045520e3ec9d9787d
Parents: 8336f7e
Author: Nandor Kollar <nk...@cloudera.com>
Authored: Fri Jun 9 00:44:37 2017 +0200
Committer: Gabor Szadovszky <ga...@apache.org>
Committed: Wed Jun 14 11:35:17 2017 +0200
----------------------------------------------------------------------
CHANGES.txt | 2 ++
.../org/apache/avro/reflect/ReflectData.java | 10 +++++---
.../org/apache/avro/reflect/TestReflect.java | 27 ++++++++++++++++++++
3 files changed, 36 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/avro/blob/c04a17c8/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index ad82ed1..d908348 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -156,6 +156,8 @@ Trunk (not yet released)
AVRO-1990: CreateRandomFileTool should validate arguments (Nandor Kollar via gabor)
+ AVRO-1401: @Nullable does not work with byte[] (Nandor Kollar via gabor)
+
Avro 1.8.1 (14 May 2016)
INCOMPATIBLE CHANGES
http://git-wip-us.apache.org/repos/asf/avro/blob/c04a17c8/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/c04a17c8/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());
+ }
}