Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8361587

AssertionError in File.listFiles() when path is empty and -esa is enabled

XMLWordPrintable

    • b07

        When a File object is instantiated using an empty string (new File("")), it resolves to the current working directory.
        As per the "java.io.File" class level specification "Accessing a file with the empty abstract pathname is equivalent to accessing the current user directory."

        However, when listFiles() is invoked on such a File instance with system assertions enabled (-esa), an unexpected AssertionError is thrown.

        `-esa` is a standard option https://docs.oracle.com/en/java/javase/24/docs/specs/man/java.html#standard-options-for-java

        This behavior is observed only when system assertions are turned on, suggesting that there's an internal assertion in the JDK code path (likely in java.io.File or related native code) that fails under this scenario.

        Sample code :
        File file = new File(""); // empty path
        File[] files = file.listFiles(); // cause AssertionError

        === possible cause ===
        private File(String child, File parent) {
                assert parent.path != null;
                ** assert (!parent.path.isEmpty());

              bpb Brian Burkhalter
              kganapureddy Krushnareddy Ganapureddy
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: