You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by ma...@apache.org on 2008/02/10 13:15:54 UTC

svn commit: r620270 - /incubator/river/jtsk/trunk/src/net/jini/loader/pref/PreferredClassLoader.java

Author: marbro
Date: Sun Feb 10 04:15:53 2008
New Revision: 620270

URL: http://svn.apache.org/viewvc?rev=620270&view=rev
Log:
Fix for RIVER-9.

Modified:
    incubator/river/jtsk/trunk/src/net/jini/loader/pref/PreferredClassLoader.java

Modified: incubator/river/jtsk/trunk/src/net/jini/loader/pref/PreferredClassLoader.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/loader/pref/PreferredClassLoader.java?rev=620270&r1=620269&r2=620270&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/loader/pref/PreferredClassLoader.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/loader/pref/PreferredClassLoader.java Sun Feb 10 04:15:53 2008
@@ -517,15 +517,17 @@
 		baseURL = firstURL;
 	    } else {
 		/*
-		 * First determine if the JAR file exists by attempting to
-		 * access it directly, without using a "jar:" URL, because
-		 * the "jar:" URL handler can mask the distinction between
-		 * definite lack of existence and less definitive errors.
-		 * Unfortunately, this direct access circumvents the JAR
+		 * First try to get a definite answer about the existence of a
+		 * PREFERRED.LIST that doesn't by-pass a JAR file cache, if
+		 * any. If that fails we determine if the JAR file exists by
+		 * attempting to access it directly, without using a "jar:" URL,
+		 * because the "jar:" URL handler can mask the distinction
+		 * between definite lack of existence and less definitive
+		 * errors. Unfortunately, this direct access circumvents the JAR
 		 * file caching done by the "jar:" handler, so it ends up
-		 * causing a duplicate request of the JAR file on first
-		 * use.  (For HTTP-protocol URLs, the initial request will
-		 * use HEAD instead of GET.)
+		 * causing duplicate requests of the JAR file on first use when
+		 * our first attempt fails. (For HTTP-protocol URLs, the initial
+		 * request will use HEAD instead of GET.)
 		 *
 		 * After determining that the JAR file exists, attempt to
 		 * retrieve the preferred list using a "jar:" URL, like
@@ -581,7 +583,26 @@
 	}
 
 	if (!exists) {
-	    exists = (getPreferredConnection(firstURL, true) != null);
+	    /*
+	     * first try to get a definite answer of the existence of a JAR
+	     * file, if no IOException is thrown when obtaining it through the
+	     * "jar:" protocol we can safely assume the JAR file is locally
+	     * available upon the attempt (elsewhere) to obtain the preferred
+	     * list
+	     */
+	    try {
+		URL baseURL = getBaseJarURL(firstURL);
+		((JarURLConnection) baseURL.openConnection()).getManifest();
+		exists = true;
+	    }
+	    catch (IOException e) {
+		// we still have no definite answer on whether the JAR file
+		// and therefore the PREFERRED.LIST exists
+	    }
+
+	    if (!exists) {
+		exists = (getPreferredConnection(firstURL, true) != null);
+	    }
 	    if (exists) {
 		synchronized (existSet) {
 		    existSet.add(firstURL);
@@ -636,8 +657,6 @@
     private URLConnection getPreferredConnection(URL url, boolean closeAfter)
 	throws IOException
     {
-	URLConnection preferredConnection = null;
-
 	if (url.getProtocol().equals("file")) {
 	    return url.openConnection();
 	}