Name: gm110360 Date: 10/11/2002
FULL PRODUCT VERSION :
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)
FULL OPERATING SYSTEM VERSION : Windows NT Version 4.0
A DESCRIPTION OF THE PROBLEM :
The method getResource from the class Class run only
outside a jar file when the file is a directory.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create the class file from this source:
2. Create a directory with the name data where the class
file is.
3. execute the program(should be ok)
4. create a jar containing this class file, and the
directory
5. execute the jar file(should be ko)
EXPECTED VERSUS ACTUAL BEHAVIOR :
Outside a jar file:
url = file:/E:/bugJar/example/classes/data
url = file:/E:/bugJar/example/classes/data/
url = file:/E:/bugJar/example/classes/data//
when the data directory is inside a jar file:
url = null
url = null
url = null
notice that with a file(ie data is a file), it's ok.
Conclusion: impossible to test if a directory exists in a
jar file.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.net.URL;
public class bugJar
{
public bugJar()
{
String dataStr = "data";
URL url = bugJar.class.getResource(dataStr);
System.out.println("url = "+url); // OK without jar
dataStr = dataStr+"/";
url = bugJar.class.getResource(dataStr);
System.out.println("url = "+url); // OK without jar
dataStr = dataStr+"\\";
url = bugJar.class.getResource(dataStr);
System.out.println("url = "+url); // OK without jar
}
public static void main(String args[])
{
new bugJar();
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
use the API java.util.jar to explicitly open the jar file.
(Review ID: 165652)
======================================================================