Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6957241

ClassLoader.getResources() returns only 1 instance when using jar indexing

    XMLWordPrintable

    Details

      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.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Imported:
                Indexed: