Skip to content

Commit f841697

Browse files
committed
[fix] convert IOException to Ruby exception correctly
follow up on: a011807 (#242)
1 parent 625ef90 commit f841697

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/main/java/org/jruby/ext/openssl/SSLSocket.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ private IRubyObject sysreadImpl(final ThreadContext context, final IRubyObject l
867867
}
868868
catch (IOException ex) {
869869
debugStackTrace(runtime, "SSLSocket.sysreadImpl", ex);
870-
throw Utils.newError(runtime, runtime.getIOError(), ex);
870+
throw Utils.newError(runtime::newIOErrorFromException, ex);
871871
}
872872
}
873873

@@ -951,7 +951,7 @@ private IRubyObject syswriteImpl(final ThreadContext context,
951951
}
952952
catch (IOException ex) {
953953
debugStackTrace(runtime, "SSLSocket.syswriteImpl", ex);
954-
throw runtime.newIOErrorFromException(ex);
954+
throw Utils.newError(runtime::newIOErrorFromException, ex);
955955
}
956956
}
957957

src/main/java/org/jruby/ext/openssl/Utils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.io.IOException;
3131
import java.nio.ByteBuffer;
3232
import java.util.HashSet;
33+
import java.util.function.Function;
3334

3435
import org.jruby.*;
3536
import org.jruby.exceptions.RaiseException;
@@ -94,6 +95,12 @@ static RaiseException newError(Ruby runtime, RubyClass errorClass, String msg, T
9495
return ex;
9596
}
9697

98+
static <T extends Throwable> RaiseException newError(Function<T, RaiseException> errorFunction, T e) {
99+
RaiseException ex = errorFunction.apply(e);
100+
ex.initCause(e);
101+
return ex;
102+
}
103+
97104
// reinvented parts of org.jruby.runtime.Helpers for compatibility with "older" JRuby :
98105

99106
static IRubyObject invoke(ThreadContext context, IRubyObject self, String name, Block block) {

0 commit comments

Comments
 (0)