Browse Source

HADOOP-6926. SocketInputStream incorrectly implements read(). Contributed by Todd Lipcon.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1031948 13f79535-47bb-0310-9956-ffa450edef68
Thomas White 14 years ago
parent
commit
f1894a3c5b

+ 3 - 0
CHANGES.txt

@@ -306,6 +306,9 @@ Trunk (unreleased changes)
     HADOOP-6758. MapFile.fix does not allow index interval definition.
     (Gianmarco De Francisci Morales via tomwhite)
 
+    HADOOP-6926. SocketInputStream incorrectly implements read().
+    (Todd Lipcon via tomwhite)
+
 Release 0.21.1 - Unreleased
 
   IMPROVEMENTS

+ 1 - 1
src/java/org/apache/hadoop/net/SocketInputStream.java

@@ -119,7 +119,7 @@ public class SocketInputStream extends InputStream
     byte[] buf = new byte[1];
     int ret = read(buf, 0, 1);
     if (ret > 0) {
-      return (byte)buf[0];
+      return (int)(buf[0] & 0xff);
     }
     if (ret != -1) {
       // unexpected

+ 3 - 0
src/test/core/org/apache/hadoop/net/TestSocketIOWithTimeout.java

@@ -101,12 +101,15 @@ public class TestSocketIOWithTimeout extends TestCase {
       
       byte[] writeBytes = TEST_STRING.getBytes();
       byte[] readBytes = new byte[writeBytes.length];
+      byte byteWithHighBit = (byte)0x80;
       
       out.write(writeBytes);
+      out.write(byteWithHighBit);
       doIO(null, out);
       
       in.read(readBytes);
       assertTrue(Arrays.equals(writeBytes, readBytes));
+      assertEquals(byteWithHighBit & 0xff, in.read());
       doIO(in, null);
       
       /*