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
This commit is contained in:
Thomas White 2010-11-06 03:13:42 +00:00
parent 3460a5e345
commit f1894a3c5b
3 changed files with 7 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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);
/*