JDK-4131169 : java.io.File: Respecify using abstract pathnames rather than strings
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.1.5,1.1.6,1.2.0
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,windows_95,windows_nt
  • CPU: generic,x86
  • Submitted: 1998-04-21
  • Updated: 1999-01-15
  • Resolved: 1999-01-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.2.0 1.2beta4Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
The java.io.File class is intended to be an abstract representation of file and
directory names.  Unfortunately it was specified in the JLS to operate in terms
of string operations and a single fixed "separator" character.  This model is
wholly inadequate for non-Unix platforms such as Win32, which have richer
pathname syntaxes involving drive letters, UNC share names, and multiple
separator characters.  The current implementation deals with some, though not
all, of these features and therefore violates the current specification.  There
are several outstanding bugs that, if fixed, would cause the implementation to
deviate further from the specification.

-- mr@eng 4/21/1998

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic FIXED IN: 1.2beta4 INTEGRATED IN: 1.2beta4
14-06-2004

PUBLIC COMMENTS .
10-06-2004

EVALUATION Awaiting review and CCC approval. Done. The final result is a little different from the suggested fix, owing to various comments received. -- mr@eng 5/14/1998
14-05-1998

SUGGESTED FIX Respecify java.io.File as follows (unmentioned methods are unchanged). This specification is believed to be compatible with both the intended behavior and the common usage of this class. /** * An abstract representation of file and directory pathnames. * * <p> User interfaces and operating systems typically use system-dependent * <em>pathname strings</em> to name files and directories. This class * presents an abstract, system-independent view of hierarchical pathnames. * An <em>abstract pathname</em> has two components: * * <ol> * <li> An optional system-dependent <em>prefix</em>, such as a disk-drive * specifier or a UNC host and share name, and * <li> A sequence of one or more <em>names</em>. * </ol> * * Each name in a pathname except for the last denotes a directory; the * last name may denote either a directory or a file. * * <p> The conversion of a pathname string to or from an abstract pathname * is inherently system-dependent. When an abstract pathname is converted * into a pathname string, each name is separated from the next by a single * copy of the default <em>separator character</em>. The default separator * character is defined by the system property <code>file.separator</code>, * and is made available in the public static fields <code>{@link * separator}</code> and <code>{@link separatorChar}</code> of this class. * When a pathname string is converted into an abstract pathname, the names * within it may be separated by the default separator character or by any * other separator character that is supported by the underlying system. * * <p> A pathname, whether abstract or in string form, may be either * <em>absolute</em> or <em>relative</em>. An absolute pathname is * complete in that no other information is required in order to locate the * unique file that it denotes. A relative pathname, in contrast, must be * interpreted in terms of a directory named by some other pathname. By * default the classes in the <code>java.io</code> package always resolve * relative pathnames against the current user directory. This directory * is named by the system property <code>user.dir</code>, and is typically * the directory in which the Java virtual machine was invoked. * * <p> Instances of the <code>File</code> class are immutable; that is, * once created, the abstract pathname represented by a <code>File</code> * object will never change. * * @since JDK1.0 */ public class java.io.File implements java.io.Serializable, Comparable { /** * The system-dependent default separator character. This field is * initialized to contain the first character of the value of the * system property <code>file.separator</code>. On UNIX sytsems, for * example, the value of this field is <code>'/'</code>, while on * Win32 systems it is <code>'\'</code>. * * @see java.lang.System#getProperty(java.lang.String) */ public static final char separatorChar; /** * The system-dependent default separator character, represented as a * string for convenience. This string contains a single character, * namely <code>{@link separatorChar}</code>. */ public static final String separator; /** * Creates a new <code>File</code> instance by converting the given * pathname string into an abstract pathname. * * @param pathname A pathname string * @exception NullPointerException * If the <code>pathname</code> argument is <code>null</code> */ public File(String pathname); /** * Creates a new <code>File</code> instance from two parent and child * pathname strings. * * <p> The <code>parent</code> pathname string denotes a directory, and * may be either relative or absolute. The <code>child</code> pathname * string denotes either a directory or a file, and must be relative. * If <code>parent</code> is <code>null</code> then the new * <code>File</code> instance is created by converting * <code>child</code> into an abstract pathname. Otherwise each * pathname string is converted into an abstract pathname and the child * abstract pathname is resolved against the parent. * * @param parent The parent pathname string * @param child The child pathname string * @exception NullPointerException * If <code>child</code> is <code>null</code> */ public File(String parent, String child); /** * Creates a new <code>File</code> instance from an abstract parent * pathname and a child pathname string. * * <p> The <code>parent</code> abstract pathname denotes a directory, * and may be either relative or absolute. The <code>child</code> * pathname string denotes either a directory or a file, and must be * relative. If <code>parent</code> is <code>null</code> then the new * <code>File</code> instance is created by converting * <code>child</code> into an abstract pathname. Otherwise the * <code>child</code> is resolved against the <code>parent</code> and * the result is converted into an abstract pathname. * * @param parent The parent abstract pathname * @param child The child pathname string * @exception NullPointerException * If <code>child</code> is <code>null</code> */ public File(File parent, String child); /** * Returns the pathname string of this abstract pathname's parent, or * <code>null</code> if this pathname does not name a parent directory. * * <p> The <em>parent</em> of an abstract pathname consists of the * pathname's prefix, if any, and each name in the pathname's name * sequence except for the last. If the name sequence is empty then * the pathname does not name a parent directory. * * @return The pathname string of the parent directory named by this * abstract pathname, or <code>null</code> if this pathname * does not name a parent */ public String getParent(); /** * Returns the name of the file or directory denoted by this abstract * pathname. This is just the last name in the pathname's name * sequence. * * @return The name of the file or directory denoted by this abstract * pathname */ public String getName(); /** * Converts this abstract pathname into a pathname string. The * resulting string uses the {@link separator; default separator * character} to separate the names in the name sequence. * * @return The string form of this abstract pathname */ public String getPath(); /** * Returns the absolute pathname string of this abstract pathname. * * <p> If this abstract pathname is already absolute, then return the * pathname string as it would be returned by the <code>{@link * getPath}</code> method. Otherwise resolve this pathname against the * current user directory, which is named by the system property * <code>user.dir</code>, and then convert it into a pathname string. * * @return An absolute pathname string denoting the same file or * directory as this abstract pathname */ public String getAbsolutePath(); /** * Returns the canonical pathname string of this abstract pathname. * * <p> The precise definition of canonical form is system-dependent, * but canonical forms are always absolute. Thus if this abstract * pathname is relative it will be resolved against the current user * directory just as in the <code>{@link getAbsolutePath}<code> method. * * <p> Every pathname that denotes an existing file or directory has a * unique canonical form. Every pathname that denotes a nonexistent * file or directory also has a unique canonical form. The canonical * form of the pathname of a nonexistent file or directory may be * different from the canonical form of the same pathname after the * file or directory is created. Similarly, the canonical form of the * pathname of an existing file or directory may be different from the * canonical form of the same pathname after the file or directory is * deleted. * * @exception IOException * If an I/O error occurs, which is possible because the * construction of the canonical pathname may require * filesystem queries * * @since JDK1.1 */ public String getCanonicalPath(); } -- mr@eng 4/21/1998
21-04-1998