Summary
Add a system property that causes access to the file system with java.io.File to fail if the file path is empty ("").
Problem
Historically, java.io.File handling of the empty path ("") was problematic, some methods work and treated it as the current directory, some methods failed. The File spec was changed in JDK 25 via JDK-8024695 so that all methods worked consistently and treated access via the empty path as access to the current directory. Unfortunately, it turns out that there is code in the eco system relying on the undocumented and inconsistent behavior. This is a larger compatibility risk that was expected when the change was proposed.
Solution
Add a system property jdk.io.File.failIfEmptyPath to make java.io.File handle the empty path as it did prior to JDK 25.
Specification
There is no specification change to File proposed here.
If the system property is set to the value "true" then it causes access to the current directory (as implied by an empty pathname string) to fail.
- csr of
-
JDK-8370216 Fix of new File("").exists() causes undefined behavior in libraries
-
- In Progress
-
- relates to
-
JDK-8024695 new File("").exists() returns false whereas it is the current working directory
-
- Resolved
-
-
JDK-8346673 new File("").exists() returns false whereas it is the current working directory
-
- Closed
-