public final class URL implements Serializable
{
private static final String DEFAULT_SEARCH_PATH =
- "gnu.java.net.protocol|sun.net.www.protocol";
+ "gnu.java.net.protocol|gnu.inet";
/**
* The name of the protocol for this URL.
*/
public String getPath()
{
+ // The spec says we need to return an empty string, but some
+ // applications depends on receiving null when the path is empty.
if (file == null)
return null;
int quest = file.indexOf('?');
* Sets the specified fields of the URL. This is not a public method so
* that only URLStreamHandlers can modify URL fields. This might be called
* by the <code>parseURL()</code> method in that class. URLs are otherwise
- * constant.
+ * constant. If the given protocol does not exist, it will keep the previously
+ * set protocol.
*
* @param protocol The protocol name for this URL
* @param host The hostname or IP address for this URL
protected void set(String protocol, String host, int port, String file,
String ref)
{
- // TBD: Theoretically, a poorly written StreamHandler could pass an
- // invalid protocol. It will cause the handler to be set to null
- // thus overriding a valid handler. Callers of this method should
- // be aware of this.
- protocol = protocol.toLowerCase ();
- if (! this.protocol.equals (protocol))
+ URLStreamHandler protocolHandler = null;
+ protocol = protocol.toLowerCase();
+ if (! this.protocol.equals(protocol))
+ protocolHandler = getURLStreamHandler(protocol);
+
+ // It is an hidden feature of the JDK. If the protocol does not exist,
+ // we keep the previously initialized protocol.
+ if (protocolHandler != null)
{
- this.ph = getURLStreamHandler(protocol);
+ this.ph = protocolHandler;
this.protocol = protocol;
}
this.authority = "";
/**
* Sets the specified fields of the URL. This is not a public method so
* that only URLStreamHandlers can modify URL fields. URLs are otherwise
- * constant.
+ * constant. If the given protocol does not exist, it will keep the previously
+ * set protocol.
*
* @param protocol The protocol name for this URL.
* @param host The hostname or IP address for this URL.
protected void set(String protocol, String host, int port, String authority,
String userInfo, String path, String query, String ref)
{
- // TBD: Theoretically, a poorly written StreamHandler could pass an
- // invalid protocol. It will cause the handler to be set to null
- // thus overriding a valid handler. Callers of this method should
- // be aware of this.
- protocol = protocol.toLowerCase ();
- if (! this.protocol.equals (protocol))
+ URLStreamHandler protocolHandler = null;
+ protocol = protocol.toLowerCase();
+ if (! this.protocol.equals(protocol))
+ protocolHandler = getURLStreamHandler(protocol);
+
+ // It is an hidden feature of the JDK. If the protocol does not exist,
+ // we keep the previously initialized protocol.
+ if (protocolHandler != null)
{
- this.ph = getURLStreamHandler(protocol);
+ this.ph = protocolHandler;
this.protocol = protocol;
}
this.host = host;