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

URL vs URI gethost

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      As I understand URL is a subset of URI, so I ran into an interesting case where the following two output gave different results

          @ParameterizedTest
          @ValueSource(
                  strings = {"http://127.0.0.1:8081", "http://dev-test:8081", "http://dev-test.01:8081"})
          void testURLAddresses(String inputAddress) {

              assertDoesNotThrow(
                      () -> {
                          final URL url = new URL(inputAddress);
                          new InetSocketAddress(url.getHost(), url.getPort());
                      });
          }

          @ParameterizedTest
          @ValueSource(
                  strings = {"http://127.0.0.1:8081", "http://dev-test:8081", "http://dev-test.01:8081"})
          void testURIAddresses(String inputAddress) {

              assertDoesNotThrow(
                      () -> {
                          final URI url = new URI(inputAddress);
                          new InetSocketAddress(url.getHost(), url.getPort());
                      });
          }



      The last case for the address "http://dev-test.01:8081" , getHost() works for URLs but for URI throws an java.lang.IllegalArgumentException: hostname can't be null




      FREQUENCY : always


            dfuchs Daniel Fuchs
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: