Skip to content

Commit

Permalink
JRUBY-5064: ChannelStream#read() should return an unsigned value.
Browse files Browse the repository at this point in the history
For InputStream compatibility. Reading int from buffered bytes works but
reading from unbeffered bytes did not work.
  • Loading branch information
Hiroshi Nakamura authored and headius committed Oct 20, 2010
1 parent 41540ef commit 6dd2bd8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/org/jruby/util/io/ChannelStream.java
Expand Up @@ -1462,7 +1462,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
Expand Down
11 changes: 11 additions & 0 deletions test/test_unmarshal.rb
Expand Up @@ -23,6 +23,17 @@ 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

# TYPE_IVAR from built-in class
class C
def _dump(depth)
Expand Down

0 comments on commit 6dd2bd8

Please sign in to comment.