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

Resources with percent encoded characters no longer load with 1.4.2_13

    XMLWordPrintable

    Details

    • Subcomponent:
    • Introduced In Version:
    • Resolved In Build:
      b02
    • CPU:
      generic
    • OS:
      generic

      Description

      As part of the fix for 4845728 that went into 1.4.2_13, 4979820 was backported from the 1.5 code base. 4979820 changed the way excluded and reserved characters (see RFC 2396) are handled by URLClassLoader and AppletClassLoader.

      This is an incompatible change for an update release, for example, a resource that previously had a ' ' (space) in its name or location needed that character to be percent encoded, %20. With this change this is nolonger the case, the space will be encoded by the implementation, but anyone using 1.4.2_xx pre _13 will know this and there code will already have the percent coding where necessary. Now with this change the characters will be doubly encoded %20 -> %2520.

      Example program that demonstractes the problem.

      Note: you need to create a resource file and put it on a http server, then update the following code to point to the appropriate location.

      ---- begin code ----
      public class TestURLClassLoader
      {
          // replace with own http server url
          static String pwd = "http://oldsunweb.ireland/~ch122065/j2se/JarRegression/";

          // percent encode any chars that require to be encoded, e.g. space, percent
          static String resStr = "space/test-dir/a%20b%20c/";

          static String resource = "resource.txt";

          public static void main(String[] args) {
              try {
                  URL[] urls = new URL[] { new URL(pwd) };
                  URLClassLoader ucl = new URLClassLoader(urls);

                  String resourceStr = resStr + resource;
                  URL resURL = ucl.getResource(resourceStr);
                  if (resURL != null) {
                      System.out.println("Resource URL = " + resURL);
                      byte[] ba = new byte[1024];
                      InputStream is = ucl.getResourceAsStream(resourceStr);
                      is.read(ba);
                      System.out.println(new String(ba));
                  }
                  else
                       System.out.println("Could not find resource");
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      }
      ---- end code ----

      Results:
      Works with 1.4.2_12 and fails with 1.4.2_13.
       Testing results:
       irejano : ./binaries/jdk1.4.2_12/bin/javac TestURLClassLoader.java
       irejano : ./binaries/jdk1.4.2_12/bin/java TestURLClassLoader
         Resource URL = http://oldsunweb.ireland/~ch122065/j2se/JarRegression/
         percent/test-dir/a%20b%20c/resource.txt
         This is from the space resource file!!!

       irejano : ./binaries/jdk1.4.2_13/bin/java TestURLClassLoader
         Could not find resource

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              coffeys Sean Coffey
              Reporter:
              chegar Chris Hegarty
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: