Skip to content

8376031: HttpsURLConnection.getServerCertificates() throws "java.lang.IllegalStateException: connection not yet open" for the HEAD method#349

Open
rm-gh-8 wants to merge 3 commits intoopenjdk:pr/348from
rm-gh-8:JDK-8376031-V25
Open

8376031: HttpsURLConnection.getServerCertificates() throws "java.lang.IllegalStateException: connection not yet open" for the HEAD method#349
rm-gh-8 wants to merge 3 commits intoopenjdk:pr/348from
rm-gh-8:JDK-8376031-V25

Conversation

@rm-gh-8
Copy link
Contributor

@rm-gh-8 rm-gh-8 commented Mar 4, 2026

Backporting JDK-8376031: HttpsURLConnection.getServerCertificates() throws "java.lang.IllegalStateException: connection not yet open" for the HEAD method.

This PR fixes HttpsURLConnection.getServerCertificates() throwing IllegalStateException after calling getResponseCode() on no-body responses by preserving the SSL session when HttpURLConnection automatically disconnects (sets http = null, connected = false) before returning the empty body stream, allowing SSL information extraction until explicit disconnect() is called.

The PR contains a modified commit that defines RSPBODY_EMPTY as a local constant rather than using a static import in the GetServerCertificates.java test, since the static import depends on JDK-8331195, which requires CSR approval before backporting.

For parity with Oracle JDK.

Ran related tests on linux-x64, linux-aarch64, macos-aarch64 and windows-x64:

make test TEST=test/jdk/sun/net/www/protocol/https/HttpsURLConnection/GetServerCertificates.java

Results attached:

windows-x64-specific-test.log
macos-aarch64-specific-test.log
linux-x64-specific-test.log
linux-aarch64-specific-test.log


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • JDK-8376031 needs maintainer approval

Integration blocker

 ⚠️ Dependency #348 must be integrated first

Issue

  • JDK-8376031: HttpsURLConnection.getServerCertificates() throws "java.lang.IllegalStateException: connection not yet open" for the HEAD method (Bug - P3 - Approved)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk25u-dev.git pull/349/head:pull/349
$ git checkout pull/349

Update a local copy of the PR:
$ git checkout pull/349
$ git pull https://git.openjdk.org/jdk25u-dev.git pull/349/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 349

View PR using the GUI difftool:
$ git pr show -t 349

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk25u-dev/pull/349.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 4, 2026

👋 Welcome back rm-gh-8! A progress list of the required criteria for merging this PR into pr/348 will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Mar 4, 2026

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot changed the title Backport d7523ec8d2255675547c0746d076efd7af5dd5af 8376031: HttpsURLConnection.getServerCertificates() throws "java.lang.IllegalStateException: connection not yet open" for the HEAD method Mar 4, 2026
@openjdk
Copy link

openjdk bot commented Mar 4, 2026

This backport pull request has now been updated with issue from the original commit.

@openjdk openjdk bot added backport Port of a pull request already in a different code base clean Identical backport; no merge resolution required labels Mar 4, 2026
@rm-gh-8 rm-gh-8 marked this pull request as ready for review March 4, 2026 19:17
@openjdk openjdk bot added the rfr Pull request is ready for review label Mar 4, 2026
@mlbridge
Copy link

mlbridge bot commented Mar 4, 2026

Webrevs

@openjdk openjdk bot removed the clean Identical backport; no merge resolution required label Mar 5, 2026
Copy link
Member

@phohensee phohensee left a comment

Choose a reason for hiding this comment

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

Please add the import of RSPBODY_EMPTY, but comment it out and add a reference to 8331195.

@rm-gh-8 rm-gh-8 requested a review from phohensee March 6, 2026 15:25
Copy link
Member

@phohensee phohensee left a comment

Choose a reason for hiding this comment

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

Thanks, good.

@rm-gh-8
Copy link
Contributor Author

rm-gh-8 commented Mar 10, 2026

/approval request for backport of JDK-8376031: HttpsURLConnection.getServerCertificates() throws "java.lang.IllegalStateException: connection not yet open" for the HEAD method.

This PR fixes HttpsURLConnection.getServerCertificates() throwing IllegalStateException after calling getResponseCode() on no-body responses by preserving the SSL session when HttpURLConnection automatically disconnects (sets http = null, connected = false) before returning the empty body stream, allowing SSL information extraction until explicit disconnect() is called.

The PR contains a modified commit that defines RSPBODY_EMPTY as a local constant rather than using a static import in the GetServerCertificates.java test, since the static import depends on JDK-8331195, which requires CSR approval before backporting.

For parity with Oracle JDK.

Low risk - the change preserves existing behavior for normal responses while fixing the edge case of empty-body responses; the saved session is properly cleared on reconnection/disconnect to prevent stale data; comprehensive test coverage validates HEAD, 204, 304, and no-body 200 responses; refactoring consolidates session access logic without changing the public API contract.

@openjdk
Copy link

openjdk bot commented Mar 10, 2026

@rm-gh-8
8376031: The approval request has been created successfully.

@openjdk openjdk bot added approval Requires approval; will be removed when approval is received and removed approval Requires approval; will be removed when approval is received labels Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Port of a pull request already in a different code base rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

2 participants