avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject [07/43] avro git commit: AVRO-1799: Fix GenericRecord#toString ByteBuffer bug.
Date Sat, 14 May 2016 23:43:40 GMT
AVRO-1799: Fix GenericRecord#toString ByteBuffer bug.

Reading the ByteBuffer to return a string representaton modified the
buffer's position. The solution is to duplicate the buffer before
reading its content.


Project: http://git-wip-us.apache.org/repos/asf/avro/repo
Commit: http://git-wip-us.apache.org/repos/asf/avro/commit/1bc650dd
Tree: http://git-wip-us.apache.org/repos/asf/avro/tree/1bc650dd
Diff: http://git-wip-us.apache.org/repos/asf/avro/diff/1bc650dd

Branch: refs/heads/branch-1.8
Commit: 1bc650dd6dbe7e87c59553e13f037481ee50abb6
Parents: ec9e1e1
Author: Ryan Blue <blue@apache.org>
Authored: Sun Feb 21 18:16:07 2016 -0800
Committer: Ryan Blue <blue@apache.org>
Committed: Sat May 14 16:43:06 2016 -0700

----------------------------------------------------------------------
 CHANGES.txt                                                      | 2 ++
 .../avro/src/main/java/org/apache/avro/generic/GenericData.java  | 2 +-
 .../src/test/java/org/apache/avro/generic/TestGenericData.java   | 4 +++-
 3 files changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/avro/blob/1bc650dd/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index cadc982..00d9deb 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -20,6 +20,8 @@ Trunk (not yet released)
     AVRO-1493. Java: Avoid the "Turkish Locale Problem". Schema fingerprints are
     now consistent regardless of the environment's locale.
 
+    AVRO-1799: Fix GenericRecord#toString ByteBuffer handling. (blue)
+
 Avro 1.8.0 (22 January 2016)
 
   INCOMPATIBLE CHANGES

http://git-wip-us.apache.org/repos/asf/avro/blob/1bc650dd/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java b/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
index 7c70631..2b01de4 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
@@ -547,7 +547,7 @@ public class GenericData {
       buffer.append("\"");
     } else if (isBytes(datum)) {
       buffer.append("{\"bytes\": \"");
-      ByteBuffer bytes = (ByteBuffer)datum;
+      ByteBuffer bytes = ((ByteBuffer) datum).duplicate();
       writeEscapedString(StandardCharsets.ISO_8859_1.decode(bytes), buffer);
       buffer.append("\"}");
     } else if (((datum instanceof Float) &&       // quote Nan & Infinity

http://git-wip-us.apache.org/repos/asf/avro/blob/1bc650dd/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericData.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericData.java b/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericData.java
index 68c33b6..b8b59e2 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericData.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericData.java
@@ -321,7 +321,9 @@ public class TestGenericData {
 
   @Test public void testToStringEscapesControlCharsInBytes() throws Exception {
     GenericData data = GenericData.get();
-    assertEquals("{\"bytes\": \"a\\nb\"}", data.toString(ByteBuffer.wrap(new byte[] {'a',
'\n', 'b'})));
+    ByteBuffer bytes = ByteBuffer.wrap(new byte[] {'a', '\n', 'b'});
+    assertEquals("{\"bytes\": \"a\\nb\"}", data.toString(bytes));
+    assertEquals("{\"bytes\": \"a\\nb\"}", data.toString(bytes));
   }
 
   @Test public void testToStringFixed() throws Exception {


Mime
View raw message