Browse Source

commit 2ff08f7a0fa76c98c2df78a93efa932d3fc9bc64
Author: Thomas White <tomwhite@apache.org>
Date: Sat Nov 6 03:13:42 2010 +0000

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


git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/yahoo-merge@1079123 13f79535-47bb-0310-9956-ffa450edef68

Owen O'Malley 14 years ago
parent
commit
1324636136

+ 3 - 0
CHANGES.txt

@@ -311,6 +311,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);
       
       /*