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 "); } } };
Fix: Fix libgcj java.io.File.java to match jdk api.
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.