Bug 6209 - java.io.File.getParent returns incorrect results
Summary: java.io.File.getParent returns incorrect results
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libgcj (show other bugs)
Version: 3.1
: P3 normal
Target Milestone: 3.3
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-04-06 15:46 UTC by awk
Modified: 2006-01-31 18:18 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description awk 2002-04-06 15:46:00 UTC
	java.io.File returns a "/" whereas it should return a "null"
	when the path name does not name a parent (i.e. the path
        name is the root directory). The following
	java class when run on a sun jdk and on gcj displays the error.

	Run on sun jdk
	% javac FileTest.java
	% java FileTest
	Canonical Name "/" Name "" Parent Name "null"

	Run on head-of-line gcj

	% gcj --main=FileTest -o FileTest FileTest.java
        % ./FileTest
        Canonical Name "/" Name "" Parent Name "/"

Release:
3.1 20020406 (prerelease)

Environment:
System: Linux panic.spinnakernet.com 2.2.14-5.0 #1 Tue Mar 7 21:07:39 EST 2000 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc/configure --host=i686-pc-linux-gnu --prefix=/spin/awk/compilers/gcc-3.1-hol --enable-shared --enable-threads=posix --enable-languages=c,c++,java --enable-version-specific-runtime-libs : (reconfigured)

How-To-Repeat:
/*
 *  Test java.io.File.getParent() on a root directory.
 */
import java.io.File;

public class FileTest {
    public static void main(String[] args) {
        try {
            File f = new File("/");
            System.out.println("Canonical Name \"" + f.getCanonicalPath()
                          + "\" Name \"" +  f.getName() + "\" Parent Name \""
                           + f.getParent() + "\"");
        } catch(Exception e) {
            System.out.println(" Exception Thrown ");
        }
    }
};
Comment 1 awk 2002-04-06 15:46:00 UTC
Fix:
	Fix libgcj java.io.File.java to match jdk api.
Comment 2 Andrew Pinski 2003-05-24 19:29:23 UTC
The mainline (20030524) and 3.3 released are fixed by:
2003-04-19  Ranjit Mathew  <rmathew@hotmail.com>

        * java/io/File.java (getAbsolutePath): On Windows, take care
        of paths like "C:", "G:foo\bar", etc.
        (getName): Make it work correctly on Windows.
        (getParent): Make it work correctly on Windows. For UNIX,
        fix bug that causes "/" to be returned as the parent of "/",
        instead of null as returned by Sun's JRE.

        * java/io/natFileWin32.cc: Change copyright owner to FSF.