diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index a008097709..569e85682b 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -188,6 +188,8 @@ Release 0.23.3 - UNRELEASED HADOOP-8104. Inconsistent Jackson versions (tucu) + HADOOP-7940. The Text.clear() method does not clear the bytes as intended. (Csaba Miklos via harsh) + Release 0.23.2 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/Text.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/Text.java index e38dd3c79a..5c52883ebf 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/Text.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/Text.java @@ -239,6 +239,7 @@ public void append(byte[] utf8, int start, int len) { */ public void clear() { length = 0; + bytes = EMPTY_BYTES; } /* diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestText.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestText.java index a7718bfba7..a756a57dae 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestText.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestText.java @@ -192,6 +192,16 @@ public void testFind() throws Exception { assertTrue(text.find("\u20ac", 5)==11); } + public void testClear() { + Text text = new Text(); + assertEquals("", text.toString()); + assertEquals(0, text.getBytes().length); + text = new Text("abcd\u20acbdcd\u20ac"); + text.clear(); + assertEquals("", text.toString()); + assertEquals(0, text.getBytes().length); + } + public void testFindAfterUpdatingContents() throws Exception { Text text = new Text("abcd"); text.set("a".getBytes());