From a806844f69225d97c2c2bb909743cdfaea27b721 Mon Sep 17 00:00:00 2001 From: Hiroshi Nakamura Date: Tue, 7 Sep 2010 14:43:39 +0900 Subject: [PATCH] JRUBY-5064: ChannelStream#read() should return an unsigned value. For InputStream compatibility. Reading int from buffered bytes works but reading from unbeffered bytes did not work. --- src/org/jruby/util/io/ChannelStream.java | 3 ++- test/test_unmarshal.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/org/jruby/util/io/ChannelStream.java b/src/org/jruby/util/io/ChannelStream.java index 3939a09381c..d06a1a53bee 100644 --- a/src/org/jruby/util/io/ChannelStream.java +++ b/src/org/jruby/util/io/ChannelStream.java @@ -1457,7 +1457,8 @@ public int read() throws IOException { } byte[] b = new byte[1]; - return read(b, 0, 1) == 1 ? b[0] : -1; + // java.io.InputStream#read must return an unsigned value; + return read(b, 0, 1) == 1 ? b[0] & 0xff: -1; } @Override diff --git a/test/test_unmarshal.rb b/test/test_unmarshal.rb index d04fd9c7c14..45f52d43155 100644 --- a/test/test_unmarshal.rb +++ b/test/test_unmarshal.rb @@ -23,4 +23,15 @@ def testUnmarshal flunk "Unmarshalling failed with EOF error at " + result + " string." end + def test_fixnum_unbuffered + # need to read unbuffered value from ChannelStream. + obj = Array.new(2000, 60803) + dump = Marshal.dump(obj) + piper, pipew = IO.pipe + pipew << dump + Marshal.load(piper).each do |e| + assert_equal(60803, e, 'JRUBY-5064') + end + end + end