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 — Auto-port 5.0: Avoid NPE in JdkSslClientContext when TrustManagerFactory returns null by netty-project-bot · Pull Request #16701 · netty/netty

Conversation

@netty-project-bot

@netty-project-bot netty-project-bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Auto-port of #16690 to 5.0
Cherry-picked commit: a96f448


Problem

Since 4.1.114, building a JDK-backed client SslContext throws an opaque SSLException caused by NullPointerException whenever the configured TrustManagerFactory returns null from getTrustManagers():

javax.net.ssl.SSLException: failed to initialize the client-side SSL context
Caused by: java.lang.NullPointerException
    at io.netty.handler.ssl.JdkSslClientContext.wrapIfNeeded(JdkSslClientContext.java:322)
    at io.netty.handler.ssl.JdkSslClientContext.newSSLContext(JdkSslClientContext.java:301)

Returning null is valid per the TrustManagerFactory contract — SSLContext.init(..., null, ...) falls back to the JDK's default trust store, and that was the working behavior in 4.1.113 and earlier.

Root Cause

4.1.114 added ResumptionController wiring. newSSLContext now routes the trust managers through a helper:

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

and wrapIfNeeded unconditionally dereferences tms.length:

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

There is no guard for tms == null, so any TrustManagerFactory whose getTrustManagers() legitimately returns null regresses with an NPE. Before 4.1.114, null flowed straight to SSLContext.init, which handled it natively.

Fix

Short-circuit wrapIfNeeded when either tms or the ResumptionController is null and return the input unchanged. null then reaches SSLContext.init exactly as it did pre-4.1.114.

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

Scope is intentionally limited to JdkSslClientContext.wrapIfNeeded, matching the reporter's observation. No other callers or formatting are touched.

Tests Added

Change point Test
wrapIfNeeded null-array guard JdkSslClientContextTest.testTrustManagerFactoryReturningNullDoesNotThrowNpe — installs a custom TrustManagerFactorySpi whose engineGetTrustManagers() returns null, builds the client SslContext via SslContextBuilder.forClient().sslProvider(JDK).trustManager(tmf), and asserts it is returned without throwing. Verified to reproduce the SSLException/NullPointerException on the pre-fix code and to pass after the fix.

All 55 tests in SslContextBuilderTest, SslContextTest, and JdkSslClientContextTest pass locally (0 failures, 0 errors, 1 pre-existing skip).

Impact

  • Restores pre-4.1.114 behavior: TrustManagerFactory implementations that return null from getTrustManagers() (i.e., "use the JDK defaults") work again with the JDK-backed SslContextBuilder.forClient().
  • Purely defensive change inside a private helper — public APIs, semantics when a non-null TrustManager[] is supplied, and the ResumptionController wrapping path are all unchanged.

Fixes #14488

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@daguimu @netty-project-bot
Avoid NPE in JdkSslClientContext when TrustManagerFactory returns null (
0ce67ab
#16690)

## Problem

Since 4.1.114, building a JDK-backed client `SslContext` throws an
opaque `SSLException` caused by `NullPointerException` whenever the
configured `TrustManagerFactory` returns `null` from
`getTrustManagers()`:

```
javax.net.ssl.SSLException: failed to initialize the client-side SSL context
Caused by: java.lang.NullPointerException
    at io.netty.handler.ssl.JdkSslClientContext.wrapIfNeeded(JdkSslClientContext.java:322)
    at io.netty.handler.ssl.JdkSslClientContext.newSSLContext(JdkSslClientContext.java:301)
```

Returning `null` is valid per the `TrustManagerFactory` contract —
`SSLContext.init(..., null, ...)` falls back to the JDK's default trust
store, and that was the working behavior in 4.1.113 and earlier.

## Root Cause

4.1.114 added `ResumptionController` wiring. `newSSLContext` now routes
the trust managers through a helper:

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

and `wrapIfNeeded` unconditionally dereferences `tms.length`:

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

There is no guard for `tms == null`, so any `TrustManagerFactory` whose
`getTrustManagers()` legitimately returns `null` regresses with an NPE.
Before 4.1.114, `null` flowed straight to `SSLContext.init`, which
handled it natively.

## Fix

Short-circuit `wrapIfNeeded` when either `tms` or the
`ResumptionController` is `null` and return the input unchanged. `null`
then reaches `SSLContext.init` exactly as it did pre-4.1.114.

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

Scope is intentionally limited to `JdkSslClientContext.wrapIfNeeded`,
matching the reporter's observation. No other callers or formatting are
touched.

## Tests Added

| Change point | Test |
|---|---|
| `wrapIfNeeded` null-array guard |
`JdkSslClientContextTest.testTrustManagerFactoryReturningNullDoesNotThrowNpe`
— installs a custom `TrustManagerFactorySpi` whose
`engineGetTrustManagers()` returns `null`, builds the client
`SslContext` via
`SslContextBuilder.forClient().sslProvider(JDK).trustManager(tmf)`, and
asserts it is returned without throwing. Verified to reproduce the
`SSLException`/`NullPointerException` on the pre-fix code and to pass
after the fix. |

All 55 tests in `SslContextBuilderTest`, `SslContextTest`, and
`JdkSslClientContextTest` pass locally (0 failures, 0 errors, 1
pre-existing skip).

## Impact

- Restores pre-4.1.114 behavior: `TrustManagerFactory` implementations
that return `null` from `getTrustManagers()` (i.e., "use the JDK
defaults") work again with the JDK-backed
`SslContextBuilder.forClient()`.
- Purely defensive change inside a private helper — public APIs,
semantics when a non-null `TrustManager[]` is supplied, and the
`ResumptionController` wrapping path are all unchanged.

Fixes #14488

(cherry picked from commit a96f448)
@netty-project-bot netty-project-bot mentioned this pull request Apr 24, 2026
Avoid NPE in JdkSslClientContext when TrustManagerFactory returns null #16690
Merged
@normanmaurer normanmaurer added this to the 5.0.0.Final milestone Apr 24, 2026
@normanmaurer
normanmaurer merged commit 31ab79a into 5.0 Apr 24, 2026
13 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer
normanmaurer deleted the auto-port-pr-16690-to-5.0 branch April 24, 2026 14:08
@normanmaurer normanmaurer mentioned this pull request Sep 22, 2026
suspend race fix #17588
Closed
@normanmaurer normanmaurer mentioned this pull request Oct 20, 2026
fix iouring zerocopy iov overwrite #17936
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

5.0.0.Final

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@netty-project-bot @normanmaurer @daguimu
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.
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.