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 — NullPointerException in JdkSslClientContext in 4.1.114.Final · Issue #14488 · netty/netty

NullPointerException in JdkSslClientContext in 4.1.114.Final #14488

New issue
Copy link
New issue
Copy link
Closed
#16702
Closed
NullPointerException in JdkSslClientContext in 4.1.114.Final#14488
#16702
Copy link

Description

@diggernet
diggernet
opened on Nov 21, 2024
Issue body actions

I've just encountered some code that works as expected with Spring Boot 3.3.4 (Netty 4.1.113.Final), but with Spring Boot 3.3.5 (Netty 4.1.114.Final) Netty throws an SSLException caused by a NullPointerException.

Expected behavior

No NullPointerException thrown, same as 4.1.113.

Actual behavior

NullPointerException thrown.

Steps to reproduce

The code calls SslContextBuilder.build() and eventually ends up in JdkSslClientContext.newSSLContext().
In 4.1.113 that method has:

    ctx.init(keyManagerFactory == null ? null : keyManagerFactory.getKeyManagers(),
        trustManagerFactory == null ? null : trustManagerFactory.getTrustManagers(),
        secureRandom);

In the code in question, getTrustManagers() returns null, null is assigned, and all is well.
In 4.1.114 that method has:

    ctx.init(keyManagerFactory == null ? null : keyManagerFactory.getKeyManagers(),
        trustManagerFactory == null ? null :
            wrapIfNeeded(trustManagerFactory.getTrustManagers(), resumptionController),
        secureRandom);

which then calls:

    private static TrustManager[] wrapIfNeeded(TrustManager[] tms, ResumptionController resumptionController) {
        if (resumptionController != null) {
            for (int i = 0; i < tms.length; i++) {
                tms[i] = resumptionController.wrapIfNeeded(tms[i]);
            }
        }
        return tms;
    }

Now when getTrustManagers() returns null, tms.length throws a NullPointerException in wrapIfNeeded().
I suspect wrapIfNeeded() ought to return null if tms is null.

Netty version

4.1.114.Final

JVM version (e.g. java -version)

17.0.11

OS version (e.g. uname -a)

Windows 10

Activity

  1. chrisvest commented on Nov 22, 2024

    @chrisvest
    chrisvest
    on Nov 22, 2024
    Member
    More actions

    Can you add the stack trace of the NullPointerException?

  2. diggernet commented on Nov 22, 2024

    @diggernet
    diggernet
    on Nov 22, 2024
    Author
    More actions

    I have to retype it manually, thanks to corporate security lockdown. :( Please forgive any typos.

    javax.net.ssl.SSLException: failed to initialize the client-side SSL context
    at io.netty.handler.ssl.JdkSslClientContext.newSSLContext(JdkSslClientContext.java:316)
    at io.netty.handler.ssl.JdkSslClientContext.(JdkSslClientContext.java:275)
    at io.netty.handler.ssl.SslContext.newClientContextInternal(SslContext.java:839)
    at io.netty.handler.ssl.SslContextBuilder.build(SslContextBuilder.java:648)
    ...
    Caused by: java.lang.NullPointerException: Cannot read the array length because "tms" is null
    at io.netty.handler.ssl.JdkSslClientContext.wrapIfNeeded(JdkSslClientContext.java:322)
    at io.netty.handler.ssl.JdkSslClientContext.newSSLContext(JdkSslClientContext.java:301)
    ...

  3. chrisvest commented on Nov 22, 2024

    @chrisvest
    chrisvest
    on Nov 22, 2024
    Member
    More actions

    Hmm… I don't think TrustManagerFactory.getTrustManagers() is allowed to return null. You have a custom TrustManagerFactory implementation that returns null?

    If you're expecting this to give you the default JDK trust implementation, why don't you just leave off specifying the TMF in your configuration?

  4. diggernet commented on Nov 23, 2024

    @diggernet
    diggernet
    on Nov 23, 2024
    Author
    More actions

    Hi Chris,
    These are all very good questions, that I wish I knew answers to. Unfortunately, I am completely unfamiliar with the calling code, and I don't know where the TrustManagerFactory comes from, or why. I only just saw this code for the first time when it started throwing exceptions as I attempted upgrading Spring Boot from 3.3.4 to 3.3.5. And the path it follows is convoluted, to say the least.

    I don't think TrustManagerFactory.getTrustManagers() is allowed to return null.

    Consider the code from 4.1.113:

        ctx.init(keyManagerFactory == null ? null : keyManagerFactory.getKeyManagers(),
            trustManagerFactory == null ? null : trustManagerFactory.getTrustManagers(),
            secureRandom);

    If trustManagerFactory.getTrustManagers() returns null, the result is indistinguishable from when trustManagerFactory is null.
    The new code in 4.1.114 changes that behavior, and appears to be an unintentional and undocumented breaking (literally) change from 4.1.113 as a result of missing a null check. Surely it is reasonable that the new code should continue to behave the same in the case of a null response, in the absence of any explicit need for it to change?

  5. daguimu
    added a commit that references this issue on Apr 23, 2026

    Avoid NPE in JdkSslClientContext when TrustManagerFactory returns null

    This issue will close once commit 6585499 is merged into the '4.1' branch.
    6585499
  6. normanmaurer
    added 3 commits that reference this issue on Apr 24, 2026

    Avoid NPE in JdkSslServerContext when TrustManagerFactory returns null (

    4a2a757

    Avoid NPE in JdkSslClientContext when TrustManagerFactory returns null (

    a96f448

    Auto-port 5.0: Avoid NPE in JdkSslClientContext when TrustManagerFact…

    31ab79a
  7. normanmaurer
    closed this as completedin #16702on Apr 24, 2026
  8. normanmaurer
    added 3 commits that reference this issue on Apr 24, 2026

    Auto-port 4.2: Avoid NPE in JdkSslClientContext when TrustManagerFact…

    This issue will close once commit 386f9d3 is merged into the '4.2' branch.
    386f9d3

    Avoid NPE in JdkSslServerContext when TrustManagerFactory returns nul… (

    This issue will close once commit 0fc37d3 is merged into the '4.2' branch.
    0fc37d3

    Auto-port 5.0: Avoid NPE in JdkSslServerContext when TrustManagerFact…

    This issue will close once commit 1dcd544 is merged into the '4.2' branch.
    1dcd544
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

      No milestone

      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.