-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.4.2
-
x86
-
linux
FULL PRODUCT VERSION :
jdk 1.4.2, 1.4.1 and alos latest 1.5.0 beta 3
ADDITIONAL OS VERSION INFORMATION :
Linux 2.4.27 and also on linux 2.6.7
EXTRA RELEVANT SYSTEM CONFIGURATION :
Not linked to a specific hardware/software configuration
A DESCRIPTION OF THE PROBLEM :
So here is the problem:
If I use a JarInputStream to open a jar, and creates URL from entry of the jar file like this :
URL u = new URL("jar:"jar.toURL()+"!/"+entry.getName());
Everything is fine, I can open a stream with the URL on the resource like this :
u.openStream().
But If I ever change the jar file (example, adding a file in it)... Then If I reopen a JarInputStream on it and recreate the same way an URL, when doing openStream it throws a FileNotFoundException.
If you just replace the jar with the same jar not modified (example by cp the jar to it), the exception does not occurs, it occurs simply if the jar file has been modified.
The strangest thing is that if I use a ZipInputStream instead of a JarInputStream, there is no problem.
Quentin Anciaux
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I provide a code snippet to reproduce the bug. Just put a jar file called "test.jar and run the class by java -cp ./ bug.testJarInputStream
It will list the content and tell if it succeed to open a stream. Then it will wait to press a key. At this time replace the "test.jar" with a modified version (example add a file in it) then press the key.. You'll have a fileNotFoundException for every entry in the jar.
Now replace the JarInputStream and JarEntry of the code snippet by ZipInputStream and ZipEntry.
Do the same, and you'll have no Exception.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No Exception like in the ZipInputStream
ACTUAL -
FileNotFoundException
ERROR MESSAGES/STACK TRACES THAT OCCUR :
ava.io.FileNotFoundException: JAR entry org/objectstyle/cayenne/project/validator/ObjRelationshipValidator.class not found in /home/qan/workspace/testJarInputStream/bin/test.jar
at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:97)
at sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:107)
at java.net.URL.openStream(URL.java:1007)
at bug.testJarInputStream.loadJarAndTestContent(testJarInputStream.java:66)
at bug.testJarInputStream.main(testJarInputStream.java:37)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
/*
* Created on 28-aot-2004
*/
package bug;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
/**
* @author Quentin Anciaux
*/
public class testJarInputStream
{
public testJarInputStream()
{
}
public static void main(String [] args)
{
testJarInputStream handler = new testJarInputStream();
try
{
handler.loadJarAndTestContent("test.jar");
handler.awaitUserInteraction();
handler.loadJarAndTestContent("test.jar");
}
catch (Exception e)
{
e.printStackTrace();
}
}
private void loadJarAndTestContent(
String pathToJarFile)
throws IOException
{
JarInputStream stream = null;
try
{
File jar = new File(pathToJarFile);
stream = new JarInputStream(new FileInputStream(pathToJarFile));
JarEntry entry = null;
while ((entry = stream.getNextJarEntry())!=null)
{
StringBuffer strURL = new StringBuffer();
strURL.append("jar:");
strURL.append(jar.toURL());
strURL.append("!/");
strURL.append(entry.getName());
URL urlToEntry = new URL(strURL.toString());
InputStream in = null;
try
{
in = urlToEntry.openStream();
System.out.println("entry URL "+urlToEntry+" is ok !");
}
catch (Exception bug)
{
bug.printStackTrace();
}
finally
{
if (in != null) in.close();
}
}
}
catch (IOException e)
{
throw e;
}
finally
{
if (stream != null) stream.close();
}
}
private void awaitUserInteraction()
{
try
{
InputStream in = System.in;
System.out.println("Change the jar file and press a key.");
in.read();
}
catch (IOException e)
{
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use ZipInputStream instead of JarInputStream
###@###.### 2004-12-10 10:46:21 GMT
jdk 1.4.2, 1.4.1 and alos latest 1.5.0 beta 3
ADDITIONAL OS VERSION INFORMATION :
Linux 2.4.27 and also on linux 2.6.7
EXTRA RELEVANT SYSTEM CONFIGURATION :
Not linked to a specific hardware/software configuration
A DESCRIPTION OF THE PROBLEM :
So here is the problem:
If I use a JarInputStream to open a jar, and creates URL from entry of the jar file like this :
URL u = new URL("jar:"jar.toURL()+"!/"+entry.getName());
Everything is fine, I can open a stream with the URL on the resource like this :
u.openStream().
But If I ever change the jar file (example, adding a file in it)... Then If I reopen a JarInputStream on it and recreate the same way an URL, when doing openStream it throws a FileNotFoundException.
If you just replace the jar with the same jar not modified (example by cp the jar to it), the exception does not occurs, it occurs simply if the jar file has been modified.
The strangest thing is that if I use a ZipInputStream instead of a JarInputStream, there is no problem.
Quentin Anciaux
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I provide a code snippet to reproduce the bug. Just put a jar file called "test.jar and run the class by java -cp ./ bug.testJarInputStream
It will list the content and tell if it succeed to open a stream. Then it will wait to press a key. At this time replace the "test.jar" with a modified version (example add a file in it) then press the key.. You'll have a fileNotFoundException for every entry in the jar.
Now replace the JarInputStream and JarEntry of the code snippet by ZipInputStream and ZipEntry.
Do the same, and you'll have no Exception.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No Exception like in the ZipInputStream
ACTUAL -
FileNotFoundException
ERROR MESSAGES/STACK TRACES THAT OCCUR :
ava.io.FileNotFoundException: JAR entry org/objectstyle/cayenne/project/validator/ObjRelationshipValidator.class not found in /home/qan/workspace/testJarInputStream/bin/test.jar
at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:97)
at sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:107)
at java.net.URL.openStream(URL.java:1007)
at bug.testJarInputStream.loadJarAndTestContent(testJarInputStream.java:66)
at bug.testJarInputStream.main(testJarInputStream.java:37)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
/*
* Created on 28-aot-2004
*/
package bug;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
/**
* @author Quentin Anciaux
*/
public class testJarInputStream
{
public testJarInputStream()
{
}
public static void main(String [] args)
{
testJarInputStream handler = new testJarInputStream();
try
{
handler.loadJarAndTestContent("test.jar");
handler.awaitUserInteraction();
handler.loadJarAndTestContent("test.jar");
}
catch (Exception e)
{
e.printStackTrace();
}
}
private void loadJarAndTestContent(
String pathToJarFile)
throws IOException
{
JarInputStream stream = null;
try
{
File jar = new File(pathToJarFile);
stream = new JarInputStream(new FileInputStream(pathToJarFile));
JarEntry entry = null;
while ((entry = stream.getNextJarEntry())!=null)
{
StringBuffer strURL = new StringBuffer();
strURL.append("jar:");
strURL.append(jar.toURL());
strURL.append("!/");
strURL.append(entry.getName());
URL urlToEntry = new URL(strURL.toString());
InputStream in = null;
try
{
in = urlToEntry.openStream();
System.out.println("entry URL "+urlToEntry+" is ok !");
}
catch (Exception bug)
{
bug.printStackTrace();
}
finally
{
if (in != null) in.close();
}
}
}
catch (IOException e)
{
throw e;
}
finally
{
if (stream != null) stream.close();
}
}
private void awaitUserInteraction()
{
try
{
InputStream in = System.in;
System.out.println("Change the jar file and press a key.");
in.read();
}
catch (IOException e)
{
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use ZipInputStream instead of JarInputStream
###@###.### 2004-12-10 10:46:21 GMT
- relates to
-
JDK-5041014 URLClassLoader.getResourceAsStream locks jar files
-
- Closed
-
-
JDK-6587593 (sl) Service provider lookup causes JAR files to be locked on Windows
-
- Closed
-