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

URL.getPort() should not return -1

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • core-libs
    • beta
    • generic
    • generic



      Name: skT45625 Date: 04/20/2000


      java version "1.3.0rc2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc2-Y)
      Java HotSpot(TM) Client VM (build 1.3.0rc2-Y, mixed mode)

      The URL.getPort() method has enough information to always return a meaningful
      response, but doesn't make the effort. I would suggest either the current
      implementation be changed to the following, or an extra method be included that
      allows the programmer to get the port number that a connection should use:

          /**
           * Returns the port number of this <code>URL</code>.
           * Returns -1 if the port is not set.
           *
           * @return the port number
           */
          public int getPort() {
            return (port != -1) ? port : handler.getDefaultPort();
          }

      This would allow the programmer to be able to open a socket, given an URL
      without having to keep a map of protocol to port numbers.

      Currently using Socket socket = new Socket(url.getHost(),url.getPort()); will
      fail when the url was constructed with "http://localhost/test.html" for no good
      reason.
        (*Chris*)
      (Review ID: 103970)
      ======================================================================

            michaelm Michael McMahon
            skondamasunw Suresh Kondamareddy (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: