[kaffe] CVS kaffe (dalibor): Resynced with GNU Classpath: URL

Kaffe CVS cvs-commits at kaffe.org
Sun Jul 11 21:42:32 PDT 2004


PatchSet 4947 
Date: 2004/07/12 04:36:31
Author: dalibor
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: URL

2004-07-11  Dalibor Topic  <robilad at kaffe.org>

        * libraries/javalib/java/net/URL.java:
        Resynced with GNU Classpath.

        2004-07-03  Mark Wielaard  <mark at klomp.org>
            Anthony Green  <green at redhat.com>

        * java/net/URL.java (getFile): Clarify return value doc.
        (getPath): Return null if file is empty - not
        empty String.

        2004-07-03  Mark Wielaard  <mark at klomp.org>
            Anthony Green  <green at redhat.com>

        * java/net/URL.java (set): Convert protocol to lower case before
        doing anything.
        Only change the protocol handler if it's different.

        2004-07-03  Anthony Green  <green at redhat.com>

        * java/net/URL.java (URL): Convert protocol to lower case before
        doing anything, so we getURLStreamHandler() with the proper
        value.

        2004-07-01  Mark Wielaard  <mark at klomp.org>

        Reported by Roman Kennke <roman at ontographics.com> (bug #9331)
        * java/net/URLStreamHandler.java (parseURL): When url file part
        doesn't contain a '/' just ignore context.

        2004-07-01  Mark Wielaard  <mark at klomp.org>

        * java/net/URL.java (systemClassLoader): New static field.
        (getURLStreamHandler): Always use system/application classloader
        for finding URLStreamhandler. Remove unecessary instanceof checks.

Members: 
	ChangeLog:1.2512->1.2513 
	libraries/javalib/java/net/URL.java:1.43->1.44 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2512 kaffe/ChangeLog:1.2513
--- kaffe/ChangeLog:1.2512	Mon Jul 12 04:29:48 2004
+++ kaffe/ChangeLog	Mon Jul 12 04:36:31 2004
@@ -14,6 +14,43 @@
 
 2004-07-11  Dalibor Topic  <robilad at kaffe.org>
 
+	* libraries/javalib/java/net/URL.java:
+	Resynced with GNU Classpath.
+
+	2004-07-03  Mark Wielaard  <mark at klomp.org>
+            Anthony Green  <green at redhat.com>
+
+        * java/net/URL.java (getFile): Clarify return value doc.
+        (getPath): Return null if file is empty - not
+        empty String.
+
+	2004-07-03  Mark Wielaard  <mark at klomp.org>
+            Anthony Green  <green at redhat.com>
+
+        * java/net/URL.java (set): Convert protocol to lower case before
+        doing anything.
+        Only change the protocol handler if it's different.
+
+	2004-07-03  Anthony Green  <green at redhat.com>
+
+        * java/net/URL.java (URL): Convert protocol to lower case before
+        doing anything, so we getURLStreamHandler() with the proper
+        value.
+
+	2004-07-01  Mark Wielaard  <mark at klomp.org>
+
+        Reported by Roman Kennke <roman at ontographics.com> (bug #9331)
+        * java/net/URLStreamHandler.java (parseURL): When url file part
+        doesn't contain a '/' just ignore context.
+
+	2004-07-01  Mark Wielaard  <mark at klomp.org>
+
+        * java/net/URL.java (systemClassLoader): New static field.
+        (getURLStreamHandler): Always use system/application classloader
+        for finding URLStreamhandler. Remove unecessary instanceof checks.
+
+2004-07-11  Dalibor Topic  <robilad at kaffe.org>
+
 	* libraries/javalib/java/net/DatagramPacket.java:
 	Resynced with GNU Classpath.
 
Index: kaffe/libraries/javalib/java/net/URL.java
diff -u kaffe/libraries/javalib/java/net/URL.java:1.43 kaffe/libraries/javalib/java/net/URL.java:1.44
--- kaffe/libraries/javalib/java/net/URL.java:1.43	Mon May 17 22:25:08 2004
+++ kaffe/libraries/javalib/java/net/URL.java	Mon Jul 12 04:36:33 2004
@@ -1,5 +1,6 @@
 /* URL.java -- Uniform Resource Locator Class
-   Copyright (C) 1998, 1999, 2000, 2002, 2003  Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004
+   Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -38,6 +39,8 @@
 package java.net;
 
 import gnu.java.net.URLParseError;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.ObjectInputStream;
@@ -123,6 +126,9 @@
   private static final String DEFAULT_SEARCH_PATH =
     "gnu.java.net.protocol|gnu.inet";
 
+  // Cached System ClassLoader
+  private static ClassLoader systemClassLoader;
+
   /**
    * The name of the protocol for this URL.
    * The protocol is always stored in lower case.
@@ -262,7 +268,8 @@
   {
     if (protocol == null)
       throw new MalformedURLException("null protocol");
-    this.protocol = protocol.toLowerCase();
+    protocol = protocol.toLowerCase();
+    this.protocol = protocol;
 
     if (ph != null)
       {
@@ -512,7 +519,7 @@
    * Defined as <code>path[?query]</code>.
    * Returns the empty string if there is no file portion.
    *
-   * @return The filename specified in this URL.
+   * @return The filename specified in this URL, or an empty string if empty.
    */
   public String getFile()
   {
@@ -523,13 +530,17 @@
    * Returns the path of the URL. This is the part of the file before any '?'
    * character.
    *
-   * @return The path specified in this URL.
+   * @return The path specified in this URL, or null if empty.
    *
    * @since 1.3
    */
   public String getPath()
   {
-    int quest = (file == null) ? -1 : file.indexOf('?');
+    // 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('?');
     return quest < 0 ? getFile() : file.substring(0, quest);
   }
 
@@ -696,14 +707,17 @@
   protected void set(String protocol, String host, int port, String file,
                      String ref)
   {
-    URLStreamHandler protocolHandler = getURLStreamHandler(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 = protocolHandler;
-        this.protocol = protocol.toLowerCase();
+	this.ph = protocolHandler;
+	this.protocol = protocol;
       }
     this.authority = "";
     this.port = port;
@@ -739,14 +753,17 @@
   protected void set(String protocol, String host, int port, String authority,
                      String userInfo, String path, String query, String ref)
   {
-    URLStreamHandler protocolHandler = getURLStreamHandler(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 = protocolHandler;
-        this.protocol = protocol.toLowerCase();
+	this.ph = protocolHandler;
+	this.protocol = protocol;
       }
     this.host = host;
     this.userInfo = userInfo;
@@ -854,36 +871,39 @@
 	// Finally loop through our search path looking for a match.
 	StringTokenizer pkgPrefix = new StringTokenizer(ph_search_path, "|");
 
-	do
+	// Cache the systemClassLoader
+	if (systemClassLoader == null)
 	  {
-	    String clsName =
-	      (pkgPrefix.nextToken() + "." + protocol + ".Handler");
+	    systemClassLoader = (ClassLoader) AccessController.doPrivileged
+	      (new PrivilegedAction() {
+		  public Object run() {
+		    return ClassLoader.getSystemClassLoader();
+		  }
+		});
+	  }
 
+	do
+	  {
 	    try
 	      {
-		Object obj = Class.forName(clsName).newInstance();
-
-		if (! (obj instanceof URLStreamHandler))
-		  continue;
-		else
-		  ph = (URLStreamHandler) obj;
-	      }
-	    catch (Exception e)
-	      {
-		// Can't instantiate; handler still null,
-		// go on to next element.
+		// Try to get a class from the system/application
+		// classloader, initialize it, make an instance
+		// and try to cast it to a URLStreamHandler.
+		String clsName =
+		  (pkgPrefix.nextToken() + "." + protocol + ".Handler");
+		Class c = Class.forName(clsName, true, systemClassLoader);
+		ph = (URLStreamHandler) c.newInstance();
 	      }
+	    catch (Throwable t) { /* ignored */ }
 	  }
-	 while ((! (ph instanceof URLStreamHandler))
-	        && pkgPrefix.hasMoreTokens());
+	 while (ph == null && pkgPrefix.hasMoreTokens());
       }
 
     // Update the hashtable with the new protocol handler.
     if (ph != null && cache_handlers)
-      if (ph instanceof URLStreamHandler)
-	ph_cache.put(protocol, ph);
-      else
-	ph = null;
+      ph_cache.put(protocol, ph);
+    else
+      ph = null;
 
     return ph;
   }




More information about the kaffe mailing list