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

java.net.URI 5-arg ctor is not verifying server authority

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 7u45, 12
    • core-libs

      A DESCRIPTION OF THE PROBLEM :
      The 5-argument constructor of java.net.URI,
        `URI​(String scheme, String authority, String path, String query, String fragment)`
       , is documented to:

      1. Construct a URI string
      2. Behave as if new URI is called with the given string and then parseServerAuthority is invoked.

      The invocation of parseServerAuthority is:

      1. Not actually performed when tried out (see code snippet below).
      2. Nonsensical, since the constructor could be used to construct a registry-based URI (otherwise the 7-arg constructor should be used).

      Example Snippet:

      According to the documentation, the snippet should print:

      Throw on 1
      Throw on 2

      However, it prints

      Throw on 2

      ----

      import java.net.URI;
      import java.net.URISyntaxException;

      public class Test {
          public static void main(String[] args) {
              try {
                  new URI(null, "my:registry", null, null, null);
              } catch (URISyntaxException e) {
                  System.out.println("Throw on 1");
              }

              try {
                  new URI("//my:registry/").parseServerAuthority();
              } catch (URISyntaxException e) {
                  System.out.println("Throw on 2");
              }
          }
      }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The resulting URI string is then parsed in order to create the new URI instance as if by invoking the URI(String) constructor; this may cause a URISyntaxException to be thrown.
      ACTUAL -
      The resulting URI string is then parsed as if by invoking the URI(String) constructor and then invoking the parseServerAuthority() method upon the result; this may cause a URISyntaxException to be thrown.

      URL OF FAULTY DOCUMENTATION :
      http://docs.oracle.com/javase/7/docs/api/java/net/URI.html#URI%28java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String%29

            chegar Chris Hegarty
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: