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

toURL() method in File class needs to escape excluded URL characters

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P2 P2
    • None
    • s8u6, solaris_8u1, 1.2.0, 1.2.1, 1.2.1_04, 1.2.2, 1.3.0, 1.3.1
    • core-libs
    • generic, x86, sparc
    • generic, solaris_2.6, solaris_8, windows_98, windows_nt

      The File class toURL() method does not escape "excluded" URL
      characters when mapping a file path to a file: URL. For example, space
      characters or '#' characters etc. should be escaped with a '%' followed by the
      hexidecimal encoding of the character.

      See RFC 2396 section 2.4.3.

      Name: rlT66838 Date: 02/15/2000


      java version "1.2.2"
      HotSpot VM (1.0.1, mixed mode, build g)

      1. Make directory, which name containts "!" sign and go to it.
      2. Create java file like:
      import java.net.*;
      import java.io.*;
      public class q
      {
          public q()
          {
              try {
                  URL u = getClass().getResource("myresources");
                  System.out.println("" + u);
                  InputStream in = u.openStream();
                  System.out.println("" + in);
                  InputStreamReader inr = new InputStreamReader(in);
               } catch (Throwable t)
              {
                  t.printStackTrace();
              }
          }
          
          public static void main(String args[])
          {
              q qq = new q();
          }
      }

      3. Create file named "myresources"
      4. Place q.class and myresources to JAR file, by example "test.jar"
      5. Run java -classpath test.jar q
      6. Look at console:
      jar:file:/M:/test/!/test.jar!/myresources
      java.util.zip.ZipException: error in opening zip file
              at java.util.zip.ZipFile.open(Native Method)
              at java.util.zip.ZipFile.<init>(ZipFile.java:69)
              at java.util.jar.JarFile.<init>(JarFile.java:71)
              at java.util.jar.JarFile.<init>(JarFile.java:58)
              at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:76)
              at sun.net.www.protocol.jar.JarURLConnection.connect
      (JarURLConnection.java:92)
              at sun.net.www.protocol.jar.JarURLConnection.getInputStream
      (JarURLConnection.java:
      112)
              at java.net.URL.openStream(URL.java:818)
              at q.<init>(q.java:10)
              at q.main(q.java:21)

      7. Place all files in, by example, "test" directory.
      Run again. All is OK.

      Problem occurs because "!" is Jar resource delimiter sign, and I think
      that either "!" must not be resource delimiter sign, or
      JarURLConnection::getResource() needed to be changed.
      (Review ID: 101275)
      ======================================================================
      ###@###.### 10/15/04 18:46 GMT

            mmcclosksunw Michael Mccloskey (Inactive)
            jdn Jeffrey Nisewanger (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: