United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-1228537 java.io.File.getParent() does not return parent directory (all platforms)
JDK-1228537 : java.io.File.getParent() does not return parent directory (all platforms)

Details
Type:
Bug
Submit Date:
1995-11-16
Status:
Closed
Updated Date:
1997-02-13
Project Name:
JDK
Resolved Date:
1997-02-13
Component:
core-libs
OS:
solaris_2.5,windows_nt
Sub-Component:
java.lang
CPU:
x86,sparc
Priority:
P3
Resolution:
Not an Issue
Affected Versions:
1.0
Fixed Versions:

Related Reports

Sub Tasks

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



Hardware and Software, Engineered to Work Together