File.exists() method returns true on Java 25, false on Java 24 and before

XMLWordPrintable

    • b12
    • 25
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      I ran this using the Eclipse Temurin distribution on both Windows 11 and macOS 26 and got the same result.

      A DESCRIPTION OF THE PROBLEM :
      After upgrading the JRE I was using in a project from Java 21 to Java 25, my code started experiencing strange bugs. I was finally able to deduce that the reason is that on Java 21 and previous versions, calling the java.io.File.exists() method on a file with an empty string as a path returns false, but in Java 25, for some reason, it returns true.

      This code, if run on Java 21 and then on Java 25, will show the issue:
      ```
      public static void main(String[] args) {
      File f = new File("");
      System.out.println(f.exists());
      }

      I can't seem to find anywhere in the Java documentation where this is mentioned as being changed from previous versions.

      From what I can see comparing the source code of this method between Java 21 and Java 25, the part using the deprecated SecurityManager is now gone, but the method still remains with no additional notes.

      REGRESSION : Last worked in version 21.0.9

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run this method on both Java 21 and Java 25.

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

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Java 21 prints "false" and Java 25 prints "true" when running the simple code above. I expected it to print "false" like all prior Java versions as a pathname of an empty string shouldn't exist.
      ACTUAL -
      The java.io.File.exists() method printed "true" instead, as if an empty-string pathname exists.

      ---------- BEGIN SOURCE ----------
      public static void main(String[] args) {
      File f = new File("");
      System.out.println(f.exists());
      }
      ---------- END SOURCE ----------

            Assignee:
            Brian Burkhalter
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: