git: openjdk/jdk21u-dev: master: 6956385: URLConnection.getLastModified() leaks file handles for jar:file and file: URLs

Victor Rudometov vrudomet at openjdk.org
Thu Mar 27 16:32:39 UTC 2025


Changeset: fc6e5755
Branch: master
Author:    Daniel Hu <costmuch at amazon.com>
Committer: Victor Rudometov <vrudomet at openjdk.org>
Date:      2025-03-27 16:30:51 +0000
URL:       https://git.openjdk.org/jdk21u-dev/commit/fc6e5755db1dd37a4f0dc295f0a49a236119e943

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

! src/java.base/share/classes/sun/net/www/protocol/file/FileURLConnection.java
! src/java.base/share/classes/sun/net/www/protocol/jar/JarURLConnection.java
+ test/jdk/sun/net/www/protocol/jar/FileURLConnectionLeak.java



More information about the jdk-updates-changes mailing list