java.io.File.getParent() bug (kaffe 1.0.b1)

Giles Lean kaffe@rufus.w3.org
Tue, 28 Jul 1998 00:06:39 +1000


Seems a popular place for bugs -- Sun have some too.  (Different ones,
of course!).

The diff below will make getParent() return "/" instead of "" when
called for a second level directory, e.g. "/tmp".  What do do in the
presence of drive letters and such I leave for someone else!

Regards,

Giles

*** libraries/javalib/java/io/File.java	1998/07/25 07:58:40	1.1
--- libraries/javalib/java/io/File.java	1998/07/25 07:55:43
***************
*** 115,122 ****
  	int slashIndex=path.lastIndexOf(separatorChar);
  	if (slashIndex==-1) {
  		return null;
! 	}
! 	else {
  		return path.substring(0, slashIndex);
  	}
  }
--- 115,123 ----
  	int slashIndex=path.lastIndexOf(separatorChar);
  	if (slashIndex==-1) {
  		return null;
! 	} else if (slashIndex==0) {
! 		return File.separator;
! 	} else {
  		return path.substring(0, slashIndex);
  	}
  }