Details
Description
ADDITIONAL SYSTEM INFORMATION :
Issue was also reproduced with Java 1.8.0_221-x64 and Java 11.0.2
A DESCRIPTION OF THE PROBLEM :
Given a jar file entry URL
When closing the InputStream created by a call to URL.openStream API
Then the close method inherited by the java.util.jar.JarFile created by the JDK is not called
And an attempt to delete the jar file using Java libraries or Windows Explorer fails with "The process cannot access the file because it is being used by another process."
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
For the below test code, create a the folder D:\temp\jdkbug and copy into it jrt-fs.jar (from the jdk).
- One can of course change the directories and adapt the code
- There's a huge chance any jar and any entry of that jar will reproduce the issue
---------- BEGIN SOURCE ----------
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
public class UrlStreamClose {
public static void main(String[] args) throws Exception {
try (InputStream is = new URL("jar:file:D:/temp/jdkbug/jrt-fs.jar!/META-INF/MANIFEST.MF").openStream()) {
System.out.println("hello");
}
Files.delete(Paths.get("D:\\temp\\jdkbug\\jrt-fs.jar"));
}
}
---------- END SOURCE ----------
FREQUENCY : always
Issue was also reproduced with Java 1.8.0_221-x64 and Java 11.0.2
A DESCRIPTION OF THE PROBLEM :
Given a jar file entry URL
When closing the InputStream created by a call to URL.openStream API
Then the close method inherited by the java.util.jar.JarFile created by the JDK is not called
And an attempt to delete the jar file using Java libraries or Windows Explorer fails with "The process cannot access the file because it is being used by another process."
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
For the below test code, create a the folder D:\temp\jdkbug and copy into it jrt-fs.jar (from the jdk).
- One can of course change the directories and adapt the code
- There's a huge chance any jar and any entry of that jar will reproduce the issue
---------- BEGIN SOURCE ----------
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
public class UrlStreamClose {
public static void main(String[] args) throws Exception {
try (InputStream is = new URL("jar:file:D:/temp/jdkbug/jrt-fs.jar!/META-INF/MANIFEST.MF").openStream()) {
System.out.println("hello");
}
Files.delete(Paths.get("D:\\temp\\jdkbug\\jrt-fs.jar"));
}
}
---------- END SOURCE ----------
FREQUENCY : always
Attachments
Issue Links
- relates to
-
JDK-8232854 URLClassLoader.close() doesn't close cached JAR file on Windows when load() fails
- Resolved
-
JDK-8132359 Amend JarURLConnection::getJarFile() to return JarFile object reference for nonexistent JAR file entry URL
- Closed
-
JDK-8246714 URLClassLoader/JAR protocol handler poisons the global JarFile cache under concurrent load
- Open
-
JDK-8338445 jdk.internal.loader.URLClassPath may leak JarFile instance when dealing with unexpected Class-Path entry in manifest
- Resolved