[jdk21u-dev] Integrated: 6956385: URLConnection.getLastModified() leaks file handles for jar:file and file: URLs

Daniel Hu duke at openjdk.org
Thu Mar 27 16:34:28 UTC 2025


On Tue, 25 Mar 2025 16:40:24 GMT, Daniel Hu <duke at openjdk.org> wrote:

> Clean backport. Fixes file handle leak if `FileURLConnection` used for `JarURLConnection`. Passes tier1 jtreg and the new test/jdk/sun/net/www/protocol/jar/FileURLConnectionLeak.java on linux x64.

This pull request has now been integrated.

Changeset: fc6e5755
Author:    Daniel Hu <costmuch at amazon.com>
Committer: Victor Rudometov <vrudomet at openjdk.org>
URL:       https://git.openjdk.org/jdk21u-dev/commit/fc6e5755db1dd37a4f0dc295f0a49a236119e943
Stats:     86 lines in 3 files changed: 84 ins; 0 del; 2 mod

6956385: URLConnection.getLastModified() leaks file handles for jar:file and file: URLs

Define FileURLConnection.closeInputStream for use by JarURLInputStream.close.
JarURLConnection properly tracks any InputStream it itself opened,
and correspondingly closes the JarFile if necessary (when caches are disabled).
But if its underlying FileURLConnection was used to retrieve a header field,
that would have caused a FileInputStream to be opened
which never gets closed until it is garbage collected.
This means that an application which calls certain methods
on jar:file:/…something.jar!/… URLs will leak file handles,
even if URLConnection caches are supposed to be turned off.
This can delay release of system resources,
and on Windows can prevent the JAR file from being deleted
even after it is no longer in use (for example after URLClassLoader.close).

Backport-of: 9f98136c3a00ca24d59ffefd58308603b58110c7

-------------

PR: https://git.openjdk.org/jdk21u-dev/pull/1546


More information about the jdk-updates-dev mailing list