Browse Source

HADOOP-453. Fix a bug in Text.setCapacity(). Contributed by Sami Siren.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@431426 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 19 years ago
parent
commit
784ea20b8e

+ 2 - 0
CHANGES.txt

@@ -22,6 +22,8 @@ Trunk (unreleased changes)
  5. HADOOP-434.  Change smallJobsBenchmark to use standard Hadoop
     scripts.  (Sanjay Dahiya via cutting)
 
+ 6. HADOOP-453.  Fix a bug in Text.setCapacity().  (siren via cutting)
+
 
 Release 0.5.0 - 2006-08-04
 

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

@@ -198,8 +198,8 @@ public class Text implements WritableComparable {
    * (if any) are deleted.
    */
   private void setCapacity( int len ) {
-    if (bytes == null || bytes.length < length)
-      bytes = new byte[length];      
+    if (bytes == null || bytes.length < len)
+      bytes = new byte[len];      
   }
    
   /** 

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

@@ -19,6 +19,7 @@ package org.apache.hadoop.io;
 import junit.framework.TestCase;
 
 import java.nio.ByteBuffer;
+import java.nio.charset.CharacterCodingException;
 import java.util.Random;
 
 import org.apache.commons.logging.Log;
@@ -199,6 +200,14 @@ public class TestText extends TestCase {
       int length = text.getLength();
       Text.validateUTF(utf8, 0, length);
   }
+
+  public void testTextText() throws CharacterCodingException {
+    Text a=new Text("abc");
+    Text b=new Text("a");
+    b.set(a);
+    assertEquals("abc",b.toString());
+  }
+
   public static void main(String[] args)  throws Exception
   {
     TestText test = new TestText("main");