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

java.io.File.getParent() does not return parent directory (all platforms)

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86, sparc
    • OS:
      solaris_2.5, windows_nt

      Description

      ###@###.### (Ken Arnold - Sun Labs

      All platforms: File.getParent() does not return the parent directory, it should return ".." or the name of the parent directory in a file-system specific way.

      If you create the File object without specifying the directory, File.getParent() returns null.


      Steps to reproduce
      Compile and run the following code

      import java.io.*;
      class FileMethods
      {
          public static void main(String[] args)
          {
             File src = new File(".", "File.java");
             
             System.out.println("getName() = " + src.getName() );
             System.out.println("getPath() = " + src.getPath());
             System.out.println("getAbsolutePath() = " + src.getAbsolutePath());
             System.out.println("getParent() = " + src.getParent());

             // without directory specified.
             src = new File("File.java");

             System.out.println("getName() = " + src.getName() );
             System.out.println("getPath() = " + src.getPath());
             System.out.println("getAbsolutePath() = " + src.getAbsolutePath());
             System.out.println("getParent() = " + src.getParent());


          }
      }

      The description field as copied from bug report 1248081 follows:


      if /tmp is set to be the value for acl.read and acl.write, then one can use
      any relative path from /tmp to access any directory. for example,
      /tmp/../home/smani --> and perform read and write operations.

      Venkat.Rao@eng wrote a sample program to verify this:

      http://hubcap.eng/secure/Test.html

        Attachments

          Activity

            People

            Assignee:
            mr Mark Reinhold
            Reporter:
            kasmithsunw Kevin Smith (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: