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

XMLWordPrintable

    • Type: CSR
    • Resolution: Unresolved
    • Priority: P4
    • 25-pool, 26
    • Component/s: core-libs
    • None
    • behavioral
    • low
    • The risk should be low as applications setting this property would be doing so to obtain the legacy behavior.
    • Java API
    • SE

      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.

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

              Created:
              Updated: