United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6957241 ClassLoader.getResources() returns only 1 instance when using jar indexing
JDK-6957241 : ClassLoader.getResources() returns only 1 instance when using jar indexing

Details
Type:
Bug
Submit Date:
2010-05-31
Status:
Open
Updated Date:
2012-03-20
Project Name:
JDK
Resolved Date:
Component:
core-libs
OS:
windows_xp
Sub-Component:
java.net
CPU:
x86
Priority:
P4
Resolution:
Unresolved
Affected Versions:
6u10
Targeted Versions:

Related Reports

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
I have a resource file (named resource.txt) that is located in 2 jar files (jar1.jar and mainJar.jar).
mainJar.jar depends on jar1.jar (I have a classpath entry in the manifest).

When I try to load the resource from mainJar using ClassLoader.getResources() I get 2 results => GOOD

Now I generate the INDEX.LIST using jar -i mainJar.jar.

Running the same test again, I now have only 1 result => BAD

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create 2 JARs with the given index in the main JAR:

JarIndex-Version: 1.0

mainJarWithIndex.jar
Main.class
resource.txt

jar1.jar
resource.txt

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Resource found = 2
ACTUAL -
Resource found = 1

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class Main {

    public static void main(String[] args) throws IOException {
        Enumeration<URL> e = Main.class.getClassLoader().getResources("resource.txt");
        int count = 0;
        while (e.hasMoreElements()) {
            URL u = e.nextElement();
            count ++;
        }
        System.out.println("Resource found = " + count);
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Do not generate INDEX.LIST but it will produce bad performances when using webstart or applet.

                                    

Comments



Hardware and Software, Engineered to Work Together