Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IO.copy_stream doesn't accept objects that respond to #readpartial #5167

Closed
janko opened this issue May 11, 2018 · 2 comments
Closed

IO.copy_stream doesn't accept objects that respond to #readpartial #5167

janko opened this issue May 11, 2018 · 2 comments
Milestone

Comments

@janko
Copy link

janko commented May 11, 2018

Environment

$ jruby -v
jruby 9.1.17.0 (2.3.3) 2018-04-20 d8b1ff9 Java HotSpot(TM) 64-Bit Server VM 25.40-b25 on 1.8.0_40-b27 +jit [darwin-x86_64]
$ uname -a
Darwin Jankos-MacBook-Pro-2.local 17.5.0 Darwin Kernel Version 17.5.0: Mon Mar  5 22:24:32 PST 2018; root:xnu-4570.51.1~1/RELEASE_X86_64 x86_64

Expected Behavior

IO.copy_stream on MRI accepts any object that responds to either #read or #readpartial as the source, so the following script works:

require "stringio"

class FakeIO
  def initialize(content)
    @io = StringIO.new(content)
  end

  def readpartial(*args)
    @io.readpartial(*args)
  end
end

IO.copy_stream(FakeIO.new("content"), File::NULL)

Actual Behavior

JRuby raises an exception when executing the above script:

ArgumentError: Should be String or IO
  copy_stream at org/jruby/RubyIO.java:4222
       <main> at script.rb:13

If I add a FakeIO#read method, the script executes without exceptions, and it calls FakeIO#read (MRI and Rubinius choose FakeIO#readpartial if both #read and #readpartial are available). It would be nice if JRuby supported #readpartial as well, it's needed for this PR.

@headius headius added this to the JRuby 9.2.0.0 milestone May 13, 2018
@headius
Copy link
Member

headius commented May 13, 2018

Thanks for the report!

@janko
Copy link
Author

janko commented May 13, 2018

Thanks for the fix! 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants