RFR: 8370216: Fix of new File("").exists() causes undefined behavior in libraries

Alan Bateman alanb at openjdk.org
Fri Nov 7 15:01:06 UTC 2025


On Wed, 5 Nov 2025 18:14:44 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> Add a system property, `jdk.io.File.failIfEmptyPath`, which when `true` reverts to legacy, pre-JDK 25 behavior, as to how `java.io.File` handles an empty pathname string.

It's problematic when the spec is clear that accessing a file with the empty path is equivalent to accessing the current directory. So I think this more as a way to get access to the current directory to fail. In any case, I think this is a forced move as we under estimated the compatibility impact of fixing the long standing inconsistency.

src/java.base/share/classes/java/io/FileSystem.java line 41:

> 39: 
> 40:     protected static final boolean FAIL_IF_EMPTY_PATH =
> 41:         Boolean.getBoolean(FAIL_IF_EMPTY_PATH_PROPERTY);

This doesn't need to be protected as FileSystem is package-private so can't be extended by classes in other package. I assume you make it protected to make it clearer that it intended for concrete subclass implementations.

-------------

Marked as reviewed by alanb (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/28158#pullrequestreview-3434490018
PR Review Comment: https://git.openjdk.org/jdk/pull/28158#discussion_r2504007892


More information about the core-libs-dev mailing list