This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: FYI: URLClassLoader.toString() fix


I'm checking this in on the trunk and the 4.0 branch.

URLClassLoader.toString() maintains a cache of its result but
neglects to reset the cache when new URLs are added.  This means
that sometimes you can see a result is confusing.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* java/net/URLClassLoader.java (addURLImpl): Reset 'thisString'.
	(toString): Synchronize.

Index: java/net/URLClassLoader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URLClassLoader.java,v
retrieving revision 1.27
diff -u -r1.27 URLClassLoader.java
--- java/net/URLClassLoader.java 16 Feb 2005 23:11:06 -0000 1.27
+++ java/net/URLClassLoader.java 9 Mar 2005 19:03:51 -0000
@@ -799,6 +799,9 @@
         if (newUrl == null)
           return; // Silently ignore...
 
+	// Reset the toString() value.
+	thisString = null;
+
         // Check global cache to see if there're already url loader
         // for this url.
         URLLoader loader = (URLLoader) urlloaders.get(newUrl);
@@ -1020,25 +1023,28 @@
    */
   public String toString()
   {
-    if (thisString == null)
+    synchronized (urlloaders)
       {
-	StringBuffer sb = new StringBuffer();
-	sb.append(this.getClass().getName());
-	sb.append("{urls=[" );
-	URL[] thisURLs = getURLs();
-	for (int i = 0; i < thisURLs.length; i++)
+	if (thisString == null)
 	  {
-	    sb.append(thisURLs[i]);
-	    if (i < thisURLs.length - 1)
-	      sb.append(',');
+	    StringBuffer sb = new StringBuffer();
+	    sb.append(this.getClass().getName());
+	    sb.append("{urls=[" );
+	    URL[] thisURLs = getURLs();
+	    for (int i = 0; i < thisURLs.length; i++)
+	      {
+		sb.append(thisURLs[i]);
+		if (i < thisURLs.length - 1)
+		  sb.append(',');
+	      }
+	    sb.append(']');
+	    sb.append(", parent=");
+	    sb.append(getParent());
+	    sb.append('}');
+	    thisString = sb.toString();
 	  }
-	sb.append(']');
-	sb.append(", parent=");
-	sb.append(getParent());
-	sb.append('}');
-	thisString = sb.toString();
+	return thisString;
       }
-    return thisString;
   }
 
   /**


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]