Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 449D1200CA7 for ; Wed, 14 Jun 2017 11:42:23 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 43189160BDB; Wed, 14 Jun 2017 09:42:23 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8ACE6160BC0 for ; Wed, 14 Jun 2017 11:42:22 +0200 (CEST) Received: (qmail 17279 invoked by uid 500); 14 Jun 2017 09:42:21 -0000 Mailing-List: contact commits-help@avro.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@avro.apache.org Delivered-To: mailing list commits@avro.apache.org Received: (qmail 17270 invoked by uid 99); 14 Jun 2017 09:42:21 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Jun 2017 09:42:21 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8782DDFF16; Wed, 14 Jun 2017 09:42:21 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: gabor@apache.org To: commits@avro.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: avro git commit: AVRO-1401: @Nullable does not work with byte[] Date: Wed, 14 Jun 2017 09:42:21 +0000 (UTC) archived-at: Wed, 14 Jun 2017 09:42:23 -0000 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 Authored: Fri Jun 9 00:44:37 2017 +0200 Committer: Gabor Szadovszky 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: + *
    + *
  • Returns true for non-string-keyed maps, which are written as an array of key/value pair records.

  • + *
  • Returns false for arrays of bytes, since those should be treated as byte data type instead.

  • + *
*/ @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()); + } }