Name: nt126004 Date: 02/25/2003
FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
If you read data from a jarfile using a jar url, you can no
longer delete the jarfile. Somewhere internally a stream to
the jarfile must be being kept open, preventing the deletion.
It seems this is only an issue on windows machines as I have
been unable to reproduce the problem on Solaris 8 or Redhat
7.2.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the attached program on Windows.
EXPECTED VERSUS ACTUAL BEHAVIOR :
After closing the input stream from the url, it should be
possible to delete the jarfile.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class JarURLTest {
public static void main(String []args) throws Exception {
// Create a wee zipfile
File mTmp = File.createTempFile("JarFileTest",".zip");
ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(mTmp));
zout.putNextEntry(new ZipEntry("blah.txt"));
zout.write("hello".getBytes());
zout.close();
// Read from the entry using a jar url
// Commenting out the following four lines allows the file to be deleted
URL u = new URL("jar:" + mTmp.toURL() + "!/blah.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(u.openStream()));
System.err.println("Read \"" + br.readLine() + "\" from " + u.toString());
br.close();
// Now attempt to delete the file.
if (!mTmp.delete()) {
System.err.println("Failed to delete file!!");
}
}
}
---------- END SOURCE ----------
(Review ID: 181418)
======================================================================