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

Invariants about java.net.URI resolve and relativize are wrong

XMLWordPrintable

    • b26
    • x86_64
    • linux_ubuntu
    • Verified

      A DESCRIPTION OF THE PROBLEM :
      The section "Operations on URI instances" states:

       Relativization, finally, is the inverse of resolution: For any two normalized URIs u and v,

          u.relativize(u.resolve(v)).equals(v) and
          u.resolve(u.relativize(v)).equals(v) .

      This is not true for at least the following two cases:

      1. Base URI (u) that doesn't end with an empty segment:

          URI u = new URI("http://a.ch/a")
          URI v = new URI("http://a.ch/a/b")
          u.resolve(u.relativize(v))
          // "http://a.ch/b" != "http://a.ch/a/b"
          u.relativize(u.resolve(v))
         // "b" != "http://a.ch/a/b"

      2. Target URI (v) that contains top-level ".." segments:

          URI u = new URI("http://a.ch/a")
          URI v = new URI("../b")
          u.resolve(u.relativize(v))
          // "http://a.ch/../b" != "../b"
          u.relativize(u.resolve(v))
          // "http://a.ch/../b" != "../b"

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      1. No invariant about relativization and resolution
      2. Proper documentation about relativization
        - how it handles non-empty segments at end of base path
        - that relativization will never introduce ".." segments
      ACTUAL -
      Relativization, finally, is the inverse of resolution: For any two normalized URIs u and v,

          u.relativize(u.resolve(v)).equals(v) and
          u.resolve(u.relativize(v)).equals(v) .


      URL OF FAULTY DOCUMENTATION :
      http://docs.oracle.com/javase/7/docs/api/java/net/URI.html

            tkiriyama Takuya Kiriyama
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: