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

A jrt URI can only encode paths to files in /modules tree

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 13
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      medium
    • Compatibility Risk Description:
      Hide
      This change may impact tools have been making use of URLs that are not compliant with the syntax. Tools with paths to files in `/packages` can use the `toRealPath()` method to obtain the real path (in `/modules`) before attempting to convert the file path to a URI.
      Show
      This change may impact tools have been making use of URLs that are not compliant with the syntax. Tools with paths to files in `/packages` can use the `toRealPath()` method to obtain the real path (in `/modules`) before attempting to convert the file path to a URI.
    • Interface Kind:
      Java API
    • Scope:
      JDK

      Description

      Summary

      The implementation of java.nio.file.Path::toUri in the jrt file system provider creates URIs that are not compliant with the syntax for jrt URIs described in JEP 220. Furthermore, the jrt file system provider's implementation of getPath(URI) does not parse jrt URLs correctly, the resulting file paths do not reliably locate files in the jrt file system.

      The CSR proposes to fix the problems in the jrt file system provider so that it creates and parses URIs that are compliant with the syntax described in JEP 220. This change may have a compatibility impact on compilers or tools relying (perhaps unknowingly) on URIs that are not compliant with the syntax.

      Problem

      Consider the file "/modules/java.base/java/lang/Object.class" in the jrt file system. If a tool has a Path to this file then invoking its toUri method should create the URI "jrt:/java.base/java/lang/Object.class". Unfortunately, due to a bug (the bug exists in JDK 9, 10, 11, 12), it yields the URI "jrt:/modules/java.base/java/lang/Object.class". This URI cannot be used with the jrt protocol handler (URL::openStream will fail with an IOException because module "modules" is not found).

      Now consider the URI "jrt:/java.base/java/lang/Object.class". If Path.of(URI) is used to create a java.nio.file.Path from this URI then the resulting jrt file path will be "/java.base/java/lang/Object.class" and so will not locate a file in the jrt file system.

      Solution

      Fix the jrt file system provider so that its Path::toUri implementation yields a URI that is compliant with the syntax. The method will fail when the file is not in the /modules tree as a jrt URI can only encode file paths to files in this tree. It will also fail if the file path is not normalized, e.g. contains ".." elements.

      Fix the jrt file system provider so that its getPath(URI) yields a file path prefixed with "/modules".

      Specification

      There are no specification changes in the CSR. This an implementation only change.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                sundar Sundararajan Athijegannathan
                Reporter:
                sundar Sundararajan Athijegannathan
                Reviewed By:
                Alan Bateman
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: