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

Daniel Hu duke at openjdk.org
Mon Mar 31 18:38:29 UTC 2025


On Thu, 27 Mar 2025 18:43:36 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.
> 
> First commit from previous dependent backport, already merged: https://github.com/openjdk/jdk17u-dev/pull/3406

This pull request has now been integrated.

Changeset: 01425e40
Author:    Daniel Hu <costmuch at amazon.com>
Committer: Paul Hohensee <phh at openjdk.org>
URL:       https://git.openjdk.org/jdk17u-dev/commit/01425e40cd545b0183d792fc6d3a82bbfb70c468
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/jdk17u-dev/pull/3409


More information about the jdk-updates-dev mailing list