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

Path.toAbsolutePath() and Path.toUri() should not throw IOError

    Details

      Description

      A DESCRIPTION OF THE PROBLEM :
      Path.toAbsolutePath() and Path.toUri() can throw IOErrors.
      IOError extends Error and therefore the following from the Error javadoc must hold true:
      >An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch.

      However, toAbsolutePath() and toUri() throw it for mundane issues like non existing paths, which violates the Error javadoc. And even the JDK suffers from this because in sun.nio.fs.WindowsLinkSupport.getRealPath it has to catch the IOError.

      Therefore please do not allow toAbsolutePath() and toUri() to throw IOErrors. Instead choose an existing RuntimeException subclass or create a new one.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the code provided below. It uses non-existent / invalid paths.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A RuntimeException should be thrown.
      ACTUAL -
      An IOError error is thrown for something as mundane as an invalid path.

      ---------- BEGIN SOURCE ----------
      try {
          // On Windows; assumes drive Z does not exist
          Path.of("Z:test").toAbsolutePath();
      } catch (IOError ioError) {
          // IOError is thrown for a non-existing path
          ioError.printStackTrace();
      }
      try {
          // Path must start with /modules, see JDK-8224946
          FileSystems.getFileSystem(URI.create("jrt:/")).getPath("/").toUri();
      } catch (IOError ioError) {
          // IOError is thrown for malformed path
          ioError.printStackTrace();
      }
      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: