Skip to content

Allow retry when UrlConnectionHttpClient encounters a NullPointerException wrapped in RuntimeException #6894

Merged
jencymaryjoseph merged 7 commits intomasterfrom
jencyjos/urlcxnhttpclient_bugfix
Apr 29, 2026
Merged

Allow retry when UrlConnectionHttpClient encounters a NullPointerException wrapped in RuntimeException #6894
jencymaryjoseph merged 7 commits intomasterfrom
jencyjos/urlcxnhttpclient_bugfix

Conversation

@jencymaryjoseph
Copy link
Copy Markdown
Contributor

@jencymaryjoseph jencymaryjoseph commented Apr 22, 2026

Motivation and Context

HttpURLConnection can throw a RuntimeException wrapping a NullPointerException (e.g., this.http is null) when the underlying connection fails unexpectedly. The SDK's UrlConnectionHttpClient already 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 IOException
  • getAndHandle100Bug() (covers getOutputStream()/getInputStream()) — wraps it as UncheckedIOException

Testing

Added unit tests in UrlConnectionHttpClientWithCustomCreateWireMockTest that simulate RuntimeException(NullPointerException) from getResponseCode(), getOutputStream(), and getInputStream(), verifying they are wrapped as IOException/UncheckedIOException

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@jencymaryjoseph jencymaryjoseph requested a review from a team as a code owner April 22, 2026 22:11
"type": "bugfix",
"category": "Url Connection Client",
"contributor": "",
"description": "Handle unhandled NullPointerException wrapped in RuntimeException when underlying connection fails with URL Connection HTTP Client"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@jencymaryjoseph jencymaryjoseph changed the title Handle unhandled NullPointerException wrapped in RuntimeException when underlying connection fails with UrlConnectionHttpClient Allow retry when UrlConnectionHttpClient encounters a NullPointerException wrapped in RuntimeException Apr 23, 2026
@jencymaryjoseph jencymaryjoseph added the no-api-surface-area-change Indicate there is no API surface area change and thus API surface area review is not required label Apr 23, 2026
@jencymaryjoseph jencymaryjoseph requested a review from dagnir April 23, 2026 17:58
@sonarqubecloud
Copy link
Copy Markdown

@jencymaryjoseph jencymaryjoseph added this pull request to the merge queue Apr 29, 2026
Merged via the queue into master with commit 47087a2 Apr 29, 2026
11 of 12 checks passed
@github-actions
Copy link
Copy Markdown

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.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

no-api-surface-area-change Indicate there is no API surface area change and thus API surface area review is not required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants