Fix JRuby SSL connection failure: use SSLContext#setup instead of freeze#627
Merged
nevans merged 1 commit intoruby:masterfrom Mar 11, 2026
Merged
Conversation
… freeze On JRuby, `OpenSSL::SSL::SSLContext#freeze` causes a NullPointerException because the internal SSL engine (`internalContext`) is lazily initialized on the first connection attempt. Freezing the object beforehand prevents that lazy write, leaving `internalContext` null and breaking all SSL connections. On CRuby, `SSLContext#setup` is effectively an alias for `freeze`, so this change is a no-op there. On JRuby (and other implementations), `setup` eagerly initializes the context without freezing the object, avoiding the NPE. Fixes: ruby#624 Co-authored-by: Nicholas Evans <nevans@users.noreply.github.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
Not a big deal, but that's incorrect. JRuby's try {
internalContext = createInternalContext(context, cert, key, store, clientCert, extraChainCert,
verifyMode, timeout, alpnProtocols, alpnSelectCb);
}
catch (GeneralSecurityException e) {
throw newSSLError(runtime, e);
}
// vvvvvvvvvvvvvvvvvv //
this.freeze(context); // <-- right here 😉
// ^^^^^^^^^^^^^^^^^^ //
return runtime.getTrue();
} |
nevans
approved these changes
Mar 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On JRuby,
OpenSSL::SSL::SSLContext#freezecauses aNullPointerExceptionbecause the internal SSL engine (internalContext) is lazily initialized on the first connection attempt. Freezing the object beforehand prevents that lazy write, leavinginternalContextnull and breaking all SSL connections.context.freezewithcontext.setupinbuild_ssl_ctxSSLContext#setupis effectively an alias forfreeze— no behavioral changesetupeagerly initializes the context without freezing, avoiding the NPEFixes #624
Co-authored-by: Nicholas Evans nevans@users.noreply.github.com