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

URL.getFile() returns different results for UNC pathnames

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3
    • None
    • 9.1pe
    • core-libs
    • None
    • generic
    • generic, windows_2000

    Description

      I am running some code on Windows, as our customer is using Windows. For the same string version of the URL (file://sm-unwk-01.sfbay.sun.com/ss141213/issue_3209.jar), URL.getFile() returns different results depending on how the URL has been created. The following code demonstrates the problem:

      import java.io.*;
      import java.net.*;
      import java.util.jar.*;
      class Test {
       public static void main(String[] args) {
         URL pxmlURL = ClassLoader.getSystemResource("META-INF/persistence.xml");
         System.out.println(pxmlURL);
         JarURLConnection conn = JarURLConnection.class.cast(pxmlURL.openConnection());
         URL url = conn.getJarFileURL();
         System.out.println(url); // prints file:/tmp/b.jar!/META-INF/persistence.xml
         System.out.println(url.getFile()); // prints
       } // main
      } // Test

      When I invoke 'java -cp \\sm-unwk-01.sfbay.sun.com\ss141213\issue_3209.jar;. Test', I get following output:

      jar:file://sm-unwk-01.sfbay.sun.com/ss141213/issue_3209.jar!/META-INF/persistence.xml
      file://sm-unwk-01.sfbay.sun.com/ss141213/issue_3209.jar
      /ss141213/issue_3209.jar

      As you can see, the UNC server name is missing in the final output. Instead of printing //sm-unwk-01.sfbay.sun.com/ss141213/issue_3209.jar, it printed /ss141213/issue_3209.jar. I have tried in both JDK 5 u4 and JDK 6 u1, and got identical results. I was even more surprised when I run the following program:

      class Test {
       public static void main(String[] args) {
        File f = new File(args[0]);
        System.out.println(f.toURL());
        System.out.println(f.toURL().getFile());
       }
      }

      When I run 'java Test \\sm-unwk-01.sfbay.sun.com\ss141213\issue_3209.jar', I get

      file://sm-unwk-01.sfbay.sun.com/ss141213/issue_3209.jar
      //sm-unwk-01.sfbay.sun.com/ss141213/issue_3209.jar

      The above output matches my expectation.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              sanjsaho Sanjeeb Sahoo
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Imported:
                Indexed: