Skip to content

Commit b84d783

Browse files
committed
[fix] NPE - do closed check retrieving channel
1 parent b32dc12 commit b84d783

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

core/src/main/java/org/jruby/util/io/OpenFile.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,37 +2578,39 @@ public ChannelFD fd() {
25782578
}
25792579

25802580
public Channel channel() {
2581-
assert(fd != null);
2581+
// MRI equivalent: rb_io_check_closed(fptr) + fptr->fd access in io.c
2582+
// when an IO was closed from another thread MRI raises IOError("closed stream") via io_fd_check_closed (io.c)
2583+
checkClosed();
25822584
return fd.ch;
25832585
}
25842586

25852587
public ReadableByteChannel readChannel() {
2586-
assert(fd != null);
2588+
checkClosed();
25872589
return fd.chRead;
25882590
}
25892591

25902592
public WritableByteChannel writeChannel() {
2591-
assert(fd != null);
2593+
checkClosed();
25922594
return fd.chWrite;
25932595
}
25942596

25952597
public SeekableByteChannel seekChannel() {
2596-
assert(fd != null);
2598+
checkClosed();
25972599
return fd.chSeek;
25982600
}
25992601

26002602
public SelectableChannel selectChannel() {
2601-
assert(fd != null);
2603+
checkClosed();
26022604
return fd.chSelect;
26032605
}
26042606

26052607
public FileChannel fileChannel() {
2606-
assert(fd != null);
2608+
checkClosed();
26072609
return fd.chFile;
26082610
}
26092611

26102612
public SocketChannel socketChannel() {
2611-
assert(fd != null);
2613+
checkClosed();
26122614
return fd.chSock;
26132615
}
26142616

0 commit comments

Comments
 (0)