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

java.io.File.getPath() does not preserve trailing separator characters

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.2.0
    • core-libs
    • None
    • generic, x86, sparc
    • generic, solaris_2.6, windows_nt


      The following example program gives different results on 1.2beta4 and 1.2beta3, 1.1.6 etc.

      import java.io.File;

      public class GetPath {
          public static void main(String args[]) {
      File f = new File("foo" + File.separatorChar);
      System.out.println("File(\"foo" + File.separatorChar + "\")" +
      " getPath() = " + f.getPath());
          }
      }

      1.2beta4 - File("foo/") getPath() = foo
      1.2beta3 - File("foo/") getPath() = foo/
      1.1.6 - File("foo/") getPath() = foo/

      In 1.2beta4, if a trailing File.separatorChar is used in the File constructor, it is not returned in File.getPath(). While in 1.2beta3 and 1.1.6 the trailing File.separatorChar is returned.

      This is not a bug really, but could break user's code which depended on this behaviour. SpecJava _213_javac broke with this change. To maintain compatibility it might be a good idea to return the trailing File.separatorChar.


            mr Mark Reinhold
            dviswanasunw Deepa Viswanathan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: