Why Does Java 25 File.exists() Method Return True for an empty string while File.exists() in prior Java versions returned False?

22 hours ago 1
ARTICLE AD BOX

The question title is self-explanatory, but basically, in the past, running File.exists() on an empty string would always return false. However, when I updated the JRE that my project was running on to Java 25, it now suddenly returns true. In other words, the following code prints out opposite values when run on different versions of the JRE:

public class Main { public static void main(String[] args) { File f = new File(""); System.out.println(f.exists()); } }

There is a way I could rewrite the code in question to not have to rely on getting a boolean from passing a potentially empty string to File.exists(), but I was wondering why the definition of this would change. Looking at the underlying source code, I do see that the implementation of this method changed with the deprecation of the SecurityManager, but I would still expect the new implementation to preserve the same outputs for the same input.

jmohrmann's user avatar

2

Read Entire Article