JDK-6545388 : Resources with percent encoded characters no longer load with 1.4.2_13
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 1.4.2_13
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2007-04-12
  • Updated: 2011-05-30
  • Resolved: 2007-05-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
1.4.2_15 b02Fixed
Related Reports
Relates :  
Relates :  
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);
                System.out.println(new String(ba));
                 System.out.println("Could not find resource");
        } catch (IOException e) {
---- end code ----

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/
   This is from the space resource file!!!

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

EVALUATION see description.