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)
======================================================================