1
0
فهرست منبع

HADOOP-3454. Fix Text::find to search only valid byte ranges. Contributed by Chad Whipkey.


git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@662667 13f79535-47bb-0310-9956-ffa450edef68
Christopher Douglas 17 سال پیش
والد
کامیت
6981258853
3فایلهای تغییر یافته به همراه12 افزوده شده و 1 حذف شده
  1. 3 0
      CHANGES.txt
  2. 1 1
      src/java/org/apache/hadoop/io/Text.java
  3. 8 0
      src/test/org/apache/hadoop/io/TestText.java

+ 3 - 0
CHANGES.txt

@@ -394,6 +394,9 @@ Trunk (unreleased changes)
     HADOOP-3443. Avoid copying map output across partitions when renaming a
     single spill. (omalley via cdouglas)
 
+    HADOOP-3454. Fix Text::find to search only valid byte ranges. (Chad Whipkey
+    via cdouglas)
+
 Release 0.17.0 - 2008-05-18
 
   INCOMPATIBLE CHANGES

+ 1 - 1
src/java/org/apache/hadoop/io/Text.java

@@ -126,7 +126,7 @@ public class Text implements WritableComparable {
    */
   public int find(String what, int start) {
     try {
-      ByteBuffer src = ByteBuffer.wrap(this.bytes);
+      ByteBuffer src = ByteBuffer.wrap(this.bytes,0,this.length);
       ByteBuffer tgt = encode(what);
       byte b = tgt.get();
       src.position(start);

+ 8 - 0
src/test/org/apache/hadoop/io/TestText.java

@@ -192,6 +192,14 @@ public class TestText extends TestCase {
     assertTrue(text.find("\u20ac", 5)==11);
   }
 
+  public void testFindAfterUpdatingContents() throws Exception {
+    Text text = new Text("abcd");
+    text.set("a".getBytes());
+    assertEquals(text.getLength(),1);
+    assertEquals(text.find("a"), 0);
+    assertEquals(text.find("b"), -1);
+  }
+
   public void testValidate() throws Exception {
     Text text = new Text("abcd\u20acbdcd\u20ac");
     byte [] utf8 = text.getBytes();