Skip to content

Commit 1913525

Browse files
committed
[fix] raise TypeError when arg not of expected type
fixes: jruby/jruby#7875
1 parent a4f2d52 commit 1913525

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,16 @@ private static CallSite callSite(final CallSite[] sites, final CallSiteIndex ind
161161
public IRubyObject initialize(final ThreadContext context, final IRubyObject[] args) {
162162
final Ruby runtime = context.runtime;
163163

164-
if ( Arity.checkArgumentCount(runtime, args, 1, 2) == 1 ) {
164+
if (Arity.checkArgumentCount(runtime, args, 1, 2) == 1) {
165165
sslContext = new SSLContext(runtime).initializeImpl();
166166
} else {
167+
if (!(args[1] instanceof SSLContext)) {
168+
throw runtime.newTypeError(args[1], "OpenSSL::SSL::SSLContext");
169+
}
167170
sslContext = (SSLContext) args[1];
168171
}
169172

170-
if ( ! ( args[0] instanceof RubyIO ) ) {
173+
if (!(args[0] instanceof RubyIO)) {
171174
throw runtime.newTypeError("IO expected but got " + args[0].getMetaClass().getName());
172175
}
173176
setInstanceVariable("@context", this.sslContext); // only compat (we do not use @context)

0 commit comments

Comments
 (0)