Browse Source

HADOOP-2738 Text is not subclassable because set(Text) and compareTo(Object) access the other instance's private members directly.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@616914 13f79535-47bb-0310-9956-ffa450edef68
Jim Kellerman 17 years ago
parent
commit
19f8c438b0
2 changed files with 8 additions and 5 deletions
  1. 3 0
      CHANGES.txt
  2. 5 5
      src/java/org/apache/hadoop/io/Text.java

+ 3 - 0
CHANGES.txt

@@ -11,6 +11,9 @@ Trunk (unreleased changes)
 
   BUG FIXES
 
+    HADOOP-2738 Text is not subclassable because set(Text) and compareTo(Object)
+    access the other instance's private members directly.
+
 Release 0.16.0 - 2008-02-04
 
   INCOMPATIBLE CHANGES

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

@@ -178,7 +178,7 @@ public class Text implements WritableComparable {
   
   /** copy a text. */
   public void set(Text other) {
-    set(other.bytes, 0, other.length);
+    set(other.getBytes(), 0, other.getLength());
   }
 
   /**
@@ -275,8 +275,9 @@ public class Text implements WritableComparable {
     if (this == that)
       return 0;
     else
-      return WritableComparator.compareBytes(bytes, 0, length,
-                                             that.bytes, 0, that.length);
+      return
+        WritableComparator.compareBytes(bytes, 0, length,
+                                        that.getBytes(), 0, that.getLength());
   }
 
   /** Returns true iff <code>o</code> is a Text with the same contents.  */
@@ -289,8 +290,7 @@ public class Text implements WritableComparable {
     else if (this.length != that.length)
       return false;
     else
-      return WritableComparator.compareBytes(bytes, 0, length,
-                                             that.bytes, 0, that.length) == 0;
+      return compareTo(o) == 0;
   }
 
   /** hash function */