JDK-1228537 : java.io.File.getParent() does not return parent directory (all platforms)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.0
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: solaris_2.5,windows_nt
  • CPU: x86,sparc
  • Submitted: 1995-11-16
  • Updated: 1997-02-13
  • Resolved: 1997-02-13
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

Comments
EVALUATION Not a bug; the reported behavior is just what the JLS specifies.
2004-06-11