A DESCRIPTION OF THE REQUEST :
If you do a:
new File("").exists();
it returns false, can cause irritations as it tells you the abstract path name if you print out:
new File("").getAbsolutePath();
So it should rather return true - which it does if you type:
File f = new File("");
new File(f.getAbsolutePath()).exists();
JUSTIFICATION :
It causes irrtitations about the function of exists, as this is not mentioned in the method comment of exists(), but it is stated, that an empty path returns the working directory.
If you are not aware of this behaviour, it can lead to severe control flow errors in your code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
return true on empty path
ACTUAL -
returns false on obviously existing path
---------- BEGIN SOURCE ----------
File f = new File("");
if(!f.exists())
System.out.println(f.getAbsolutePath());
System.out.println("But it does exist: " + new File(f.getAbsolutePath()).exists());
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
File f = new File("");
new File(f.getAbsolutePath()).exists();
If you do a:
new File("").exists();
it returns false, can cause irritations as it tells you the abstract path name if you print out:
new File("").getAbsolutePath();
So it should rather return true - which it does if you type:
File f = new File("");
new File(f.getAbsolutePath()).exists();
JUSTIFICATION :
It causes irrtitations about the function of exists, as this is not mentioned in the method comment of exists(), but it is stated, that an empty path returns the working directory.
If you are not aware of this behaviour, it can lead to severe control flow errors in your code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
return true on empty path
ACTUAL -
returns false on obviously existing path
---------- BEGIN SOURCE ----------
File f = new File("");
if(!f.exists())
System.out.println(f.getAbsolutePath());
System.out.println("But it does exist: " + new File(f.getAbsolutePath()).exists());
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
File f = new File("");
new File(f.getAbsolutePath()).exists();
- csr for
-
JDK-8346673 new File("").exists() returns false whereas it is the current working directory
-
- Closed
-
- relates to
-
JDK-8349092 File.getFreeSpace violates specification if quotas are in effect (win)
-
- Resolved
-
-
JDK-8349812 (fs) Files.newByteChannel with empty path name and CREATE_NEW throws unexpected exception
-
- Resolved
-
-
JDK-4271369 (spec) File.list() should document behaviour if path is the empty string
-
- Open
-
- links to
-
Commit(master) openjdk/jdk/9477c705
-
Review(master) openjdk/jdk/22821
(1 links to)