hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r908680 - in /hadoop/common/branches/branch-0.21: CHANGES.txt src/java/org/apache/hadoop/io/UTF8.java src/test/core/org/apache/hadoop/io/TestUTF8.java
Date Wed, 10 Feb 2010 22:15:14 GMT
Author: cutting
Date: Wed Feb 10 22:14:39 2010
New Revision: 908680

URL: http://svn.apache.org/viewvc?rev=908680&view=rev
Log:
HADOOP-6522.  Fix decoding of codepoint zero in UTF8.

Modified:
    hadoop/common/branches/branch-0.21/CHANGES.txt
    hadoop/common/branches/branch-0.21/src/java/org/apache/hadoop/io/UTF8.java
    hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/io/TestUTF8.java

Modified: hadoop/common/branches/branch-0.21/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.21/CHANGES.txt?rev=908680&r1=908679&r2=908680&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.21/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.21/CHANGES.txt Wed Feb 10 22:14:39 2010
@@ -1147,6 +1147,8 @@
     HADOOP-6290. Prevent duplicate slf4j-simple jar via Avro's classpath.
     (Owen O'Malley via cdouglas)
 
+    HADOOP-6522. Fix decoding of codepoint zero in UTF8. (cutting)
+
 Release 0.20.2 - Unreleased
 
   NEW FEATURES

Modified: hadoop/common/branches/branch-0.21/src/java/org/apache/hadoop/io/UTF8.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.21/src/java/org/apache/hadoop/io/UTF8.java?rev=908680&r1=908679&r2=908680&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.21/src/java/org/apache/hadoop/io/UTF8.java (original)
+++ hadoop/common/branches/branch-0.21/src/java/org/apache/hadoop/io/UTF8.java Wed Feb 10
22:14:39 2010
@@ -253,7 +253,7 @@
     int utf8Length = 0;
     for (int i = 0; i < stringLength; i++) {
       int c = string.charAt(i);
-      if ((c >= 0x0001) && (c <= 0x007F)) {
+      if (c <= 0x007F) {
         utf8Length++;
       } else if (c > 0x07FF) {
         utf8Length += 3;
@@ -270,7 +270,7 @@
     final int end = start + length;
     for (int i = start; i < end; i++) {
       int code = s.charAt(i);
-      if (code >= 0x01 && code <= 0x7F) {
+      if (code <= 0x7F) {
         out.writeByte((byte)code);
       } else if (code <= 0x07FF) {
         out.writeByte((byte)(0xC0 | ((code >> 6) & 0x1F)));

Modified: hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/io/TestUTF8.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/io/TestUTF8.java?rev=908680&r1=908679&r2=908680&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/io/TestUTF8.java (original)
+++ hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/io/TestUTF8.java Wed
Feb 10 22:14:39 2010
@@ -22,6 +22,7 @@
 import java.util.Random;
 
 /** Unit tests for UTF8. */
+@SuppressWarnings("deprecation")
 public class TestUTF8 extends TestCase {
   public TestUTF8(String name) { super(name); }
 
@@ -37,13 +38,13 @@
   }
 
   public void testWritable() throws Exception {
-    for (int i = 0; i < 10; i++) {
+    for (int i = 0; i < 10000; i++) {
       TestWritable.testWritable(new UTF8(getTestString()));
     }
   }
 
   public void testGetBytes() throws Exception {
-    for (int i = 0; i < 10; i++) {
+    for (int i = 0; i < 10000; i++) {
 
       // generate a random string
       String before = getTestString();
@@ -57,7 +58,7 @@
     DataOutputBuffer out = new DataOutputBuffer();
     DataInputBuffer in = new DataInputBuffer();
 
-    for (int i = 0; i < 10; i++) {
+    for (int i = 0; i < 10000; i++) {
       // generate a random string
       String before = getTestString();
 
@@ -82,5 +83,14 @@
     }
 
   }
+
+  public void testNullEncoding() throws Exception {
+    String s = new String(new char[] { 0 });
+
+    DataOutputBuffer dob = new DataOutputBuffer();
+    new UTF8(s).write(dob);
+
+    assertEquals(s, new String(dob.getData(), 2, dob.getLength()-2, "UTF-8"));
+  }
 	
 }



Mime
View raw message