GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BouncyCastleAlpnSslUtils static initializer fails when using a Security Properties file · Issue #15508 · netty/netty

BouncyCastleAlpnSslUtils static initializer fails when using a Security Properties file #15508

New issue
Copy link
New issue
Copy link
Closed
#15569
Closed
BouncyCastleAlpnSslUtils static initializer fails when using a Security Properties file#15508
#15569
Copy link
Milestone
4.2.5.Final

Description

@scotthraban
scotthraban
opened on Jul 19, 2025
Issue body actions

When using a Security Properties file to configure the SecurityProviders, the System classloader is used to load the SecurityProviders.

This leads to problems when using BouncyCastleAlpnSslUtils, leading to the "Unable to initialize BouncyCastleAlpnSslUtils." error, with the stack trace being (on version 4.1.122.Final):

java.lang.IllegalArgumentException: object is not an instance of declaring class
 	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.checkReceiver(DirectMethodHandleAccessor.java:197)
 	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:99)
 	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
 	at io.netty.handler.ssl.BouncyCastleAlpnSslUtils.<clinit>(BouncyCastleAlpnSslUtils.java:89)

The problem starts with lines 63 - 64, with the call to Class.forName(), which uses the classloader of the caller, which is generally the ApplicationClassLoader.

            bcSslEngine = Class.forName("org.bouncycastle.jsse.BCSSLEngine");
            final Class testBCSslEngine = bcSslEngine;

However, a bit farther down, on lines 79 - 80, an SSLContext and SSLEngine are created, and since these are created from the Provider that was loaded by the SystemClassLoader, they themselves are loaded by the SystemClassLoader.

            SSLContext context = getSSLContext("BCJSSE");
            SSLEngine engine = context.createSSLEngine();

Then when the attempt is made to invoke the getMethod call on line 89, the engine instance (in my case a org.bouncycastle.jsse.provider.ProvSSLEngine_9) does not implement the org.bouncycastle.jsse.BCSSLEngine class that is loaded on line 63, because they are in different class loaders.

            final Object bcSslParameters = getParameters.invoke(engine);

I believe that this can be fixed by applying the pattern seen in a number of other places in the repo, of enhancing the call to Class.forName() to pass in the class loader to use, instead of the one of the caller.

I prototyped this locally by copying the code out of the static initializer, and creating the engine first before calling:

            SSLContext context = getSSLContext("BCJSSE");
            SSLEngine engine = context.createSSLEngine();

            bcSslEngine = Class.forName("org.bouncycastle.jsse.BCSSLEngine", true, engine.getClass().getClassloader());

            getParameters = AccessController.doPrivileged(new PrivilegedExceptionAction<Method>() {
                @Override
                public Method run() throws Exception {
                    return testBCSslEngine.getMethod("getParameters");
                }
            });

            final Object bcSslParameters = getParameters.invoke(engine);

Then the .invoke() method no longer throws the exception.

I imagine the same pattern would need to be applied to any number of other Class.forName() calls in this class, and maybe in others as well.

Reacted by llh4github

Activity

  1. normanmaurer commented on Aug 7, 2025

    @normanmaurer
    normanmaurer
    on Aug 7, 2025
    Member
    More actions

    @chrisvest can you have a l look ?

    Reacted by Chris Vest
  2. chrisvest
    added a commit that references this issue on Aug 9, 2025

    Always load BouncyCastle classes with the Netty classloader

    3506da0
  3. chrisvest commented on Aug 9, 2025

    @chrisvest
    chrisvest
    on Aug 9, 2025
    Member
    More actions

    @scotthraban I think this should do it: #15533

  4. chrisvest
    added 2 commits that reference this issue on Aug 18, 2025

    Always load BouncyCastle classes with the Netty classloader (#15533)

    623d204

    Always load BouncyCastle classes with the Netty classloader (netty#15533

    fd956d9
  5. normanmaurer
    closed this as completedin #15569on Aug 19, 2025
  6. normanmaurer
    added 3 commits that reference this issue on Aug 19, 2025

    Always load BouncyCastle classes with the Netty classloader (#15533) (#…

    c90f2de

    Always load BouncyCastle classes with the Netty classloader (#15533) (#…

    74a2097

    Always load BouncyCastle classes with the Netty classloader (#15533) … (

    535b50f
  7. normanmaurer
    added this to the 4.2.5.Final milestone on Aug 19, 2025
  8. chrisvest
    added a commit that references this issue on Aug 19, 2025

    Always load BouncyCastle classes with the Netty classloader (netty#15533

    b21980a
  9. normanmaurer
    added a commit that references this issue on Aug 20, 2025

    Always load BouncyCastle classes with the Netty classloader (#15533) (#…

    cb84882
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      • 4.2.5.Final

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.