JDK-6957241 : ClassLoader.getResources() returns only 1 instance when using jar indexing
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 6u10
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2010-05-31
  • Updated: 2012-03-20
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.