Skip to content

Commit

Permalink
[fix] raise TypeError when arg not of expected type
Browse files Browse the repository at this point in the history
  • Loading branch information
kares committed Aug 11, 2023
1 parent a4f2d52 commit 1913525
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/java/org/jruby/ext/openssl/SSLSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,16 @@ private static CallSite callSite(final CallSite[] sites, final CallSiteIndex ind
public IRubyObject initialize(final ThreadContext context, final IRubyObject[] args) {
final Ruby runtime = context.runtime;

if ( Arity.checkArgumentCount(runtime, args, 1, 2) == 1 ) {
if (Arity.checkArgumentCount(runtime, args, 1, 2) == 1) {
sslContext = new SSLContext(runtime).initializeImpl();
} else {
if (!(args[1] instanceof SSLContext)) {
throw runtime.newTypeError(args[1], "OpenSSL::SSL::SSLContext");
}
sslContext = (SSLContext) args[1];
}

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

0 comments on commit 1913525

Please sign in to comment.