diff --git a/CHANGES.txt b/CHANGES.txt index 6a1c958d44..80e8640a84 100644 --- a/CHANGES.txt +++ b/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 diff --git a/src/java/org/apache/hadoop/net/SocketInputStream.java b/src/java/org/apache/hadoop/net/SocketInputStream.java index 2efe765cd8..ef8c02b7dd 100644 --- a/src/java/org/apache/hadoop/net/SocketInputStream.java +++ b/src/java/org/apache/hadoop/net/SocketInputStream.java @@ -119,7 +119,7 @@ public int read() throws IOException { 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 diff --git a/src/test/core/org/apache/hadoop/net/TestSocketIOWithTimeout.java b/src/test/core/org/apache/hadoop/net/TestSocketIOWithTimeout.java index 53f320917c..0c887eb82b 100644 --- a/src/test/core/org/apache/hadoop/net/TestSocketIOWithTimeout.java +++ b/src/test/core/org/apache/hadoop/net/TestSocketIOWithTimeout.java @@ -101,12 +101,15 @@ public void testSocketIOWithTimeout() throws IOException { 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); /*