Allow retry when UrlConnectionHttpClient encounters a NullPointerException wrapped in RuntimeException #6894
Merged
jencymaryjoseph merged 7 commits intomasterfrom Apr 29, 2026
Merged
Conversation
dagnir
reviewed
Apr 23, 2026
| "type": "bugfix", | ||
| "category": "Url Connection Client", | ||
| "contributor": "", | ||
| "description": "Handle unhandled NullPointerException wrapped in RuntimeException when underlying connection fails with URL Connection HTTP Client" |
Contributor
There was a problem hiding this comment.
Since "handle" is a vague term, we can replace it with something more specific like "treat as IOException to allow a retry" or something like that
|
dagnir
approved these changes
Apr 24, 2026
|
This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.



Motivation and Context
HttpURLConnectioncan throw a RuntimeException wrapping a NullPointerException (e.g., this.http is null) when the underlying connection fails unexpectedly. The SDK'sUrlConnectionHttpClientalready handles bare NullPointerException from getResponseCode(), but does not handle the case where the NPE is wrapped in a RuntimeException. This causes the unhandled RuntimeException to propagate up instead of being converted to an IOException, which breaks the SDK's retry logic since retries only trigger on IOException.Modifications
In
UrlConnectionHttpClient, added handling for RuntimeException with an NPE cause in three places:getResponseCode() — wraps it as IOExceptiongetAndHandle100Bug() (covers getOutputStream()/getInputStream()) — wraps it as UncheckedIOExceptionTesting
Added unit tests in
UrlConnectionHttpClientWithCustomCreateWireMockTestthat simulate RuntimeException(NullPointerException) fromgetResponseCode(),getOutputStream(), andgetInputStream(), verifying they are wrapped as IOException/UncheckedIOExceptionScreenshots (if appropriate)
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License