Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1dc7967b4f74
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 05e6e7e1090d
Choose a head ref
  • 2 commits
  • 4 files changed
  • 2 contributors

Commits on Dec 13, 2015

  1. [ruby 2.3 Feature #10718] IO#close should not raise IOError on closed…

    … IO objects.
    
    IO#close now silently returns nil if called on an already-closed IO object.
    cheald committed Dec 13, 2015
    Copy the full SHA
    9ab7d1c View commit details
  2. Merge pull request #3536 from cheald/io_silent_close

    [ruby 2.3 Feature #10718] IO#close should not raise IOError on closed IO objects.
    nirvdrum committed Dec 13, 2015
    Copy the full SHA
    05e6e7e View commit details
Showing with 18 additions and 4 deletions.
  1. +4 −2 core/src/main/java/org/jruby/RubyIO.java
  2. +12 −0 test/mri/ruby/test_io.rb
  3. +1 −1 test/mri/socket/test_basicsocket.rb
  4. +1 −1 test/mri/zlib/test_zlib.rb
6 changes: 4 additions & 2 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
@@ -1943,14 +1943,16 @@ public boolean isClosed() {
* <p>Closes all open resources for the IO. It also removes
* it from our magical all open file descriptor pool.</p>
*
* @return The IO.
* @return The IO. Returns nil if the IO was already closed.
*
* MRI: rb_io_close_m
*/
@JRubyMethod
public IRubyObject close() {
Ruby runtime = getRuntime();

if (isClosed()) {
return runtime.getNil();
}
openFile.checkClosed();
return rbIoClose(runtime);
}
12 changes: 12 additions & 0 deletions test/mri/ruby/test_io.rb
Original file line number Diff line number Diff line change
@@ -3146,4 +3146,16 @@ def test_exception_at_close
end
end
end

def test_close_twice
open(__FILE__) {|f|
assert_equal(nil, f.close)
assert_equal(nil, f.close)
}
end

def test_close_uninitialized
io = IO.allocate
assert_raise(IOError) { io.close }
end
end
2 changes: 1 addition & 1 deletion test/mri/socket/test_basicsocket.rb
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ def inet_stream
sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
yield sock
ensure
assert_raise(IOError) {sock.close}
assert(sock.closed?)
end

def test_getsockopt
2 changes: 1 addition & 1 deletion test/mri/zlib/test_zlib.rb
Original file line number Diff line number Diff line change
@@ -929,7 +929,7 @@ def test_reader_wrap
f = open(t.path)
f.binmode
assert_equal("foo", Zlib::GzipReader.wrap(f) {|gz| gz.read })
assert_raise(IOError) { f.close }
assert(f.closed?)
}
end