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

java.net.URL allows to create URL with port > 65535

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      URL(string) constructor doesn't check port > 65535.
      By the way this API is already @Deprecated(since = "20").


      ---------- BEGIN SOURCE ----------

      import java.net.*;

      public class URLTest {
          public static void main(String args[]) throws Exception {
              try {
                  URL url = new URL("http://[fe80::]:999999/path1/path2");
                  System.out.println(url.getPort());
                  throw new RuntimeException("URL parser accepted invalid port number");
              } catch (MalformedURLException me) {
                  System.out.println("Caught expected exception (invalid port): " + me.getMessage());
              }
          }
      }

      ---------- END SOURCE ----------

            asajeev Anjana Sajeev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: