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

java.net.URI initialized incorrectly with non-alphanumeric hostname

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 11.0.4
    • core-libs
    • x86_64
    • linux

      A DESCRIPTION OF THE PROBLEM :
      When creating a java.net.URI object with a host that does not conform to the RFC, an exception is not thrown but many sections of the URI are not parsed to fields in the URI object. This leaves the URI in an inconsistent state without informing the caller of any issues.

      If the URI is deemed to be invalid, an exception should be thrown (as documented), otherwise the URI object should be completely filled out.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a new java.net.URI object with a URI containing an invalid character in the hostname:

      java.net.URI uri = new java.net.URI("http://my_host.com:1234")

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Either a URISyntaxException should be thrown, or the URI should be created with all fields populated
      ACTUAL -
      No exception is thrown, but uri.getHost() returns null and uri.getPort() returns -1

      ---------- BEGIN SOURCE ----------
      //If URI will be considered valid
      @Test
      void uriTestConsisderedValid() {
        URI uri = URI.create("http://my_host.com:1234");
        assertEquals("http", uri.getScheme());
        assertEquals("my_host", uri.getHost());
        assertEquals(1234, uri.getPort());
      }
      //If URI will be considered invalid
      @Test
      void uriTestConsideredInvalid() {
        assertThrows(IllegalArgumentException.class, () -> URI.create("http://my_host.com:1234"));
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: