river-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter_firmst...@apache.org
Subject svn commit: r1362452 - /river/jtsk/trunk/src/net/jini/loader/pref/PreferredClassProvider.java
Date Tue, 17 Jul 2012 11:35:23 GMT
Author: peter_firmstone
Date: Tue Jul 17 11:35:23 2012
New Revision: 1362452

URL: http://svn.apache.org/viewvc?rev=1362452&view=rev
Log:
Feeble attempt to fix failing test on Hudson Windows:

com/sun/jini/test/impl/locatordiscovery/BadLocatorDiscoveryListener.td

The commit may be reversed, I suspect that at class initialisation time of PreferredClassProvider
the java Policy file has been instantiated, however it hasn't handed over to our policy implementation
yet.  Try using lazy loading to avoid requiring RuntimePermission("getClassLoader") until
after class initialisation has completed.

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

Modified: river/jtsk/trunk/src/net/jini/loader/pref/PreferredClassProvider.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/net/jini/loader/pref/PreferredClassProvider.java?rev=1362452&r1=1362451&r2=1362452&view=diff
==============================================================================
--- river/jtsk/trunk/src/net/jini/loader/pref/PreferredClassProvider.java (original)
+++ river/jtsk/trunk/src/net/jini/loader/pref/PreferredClassProvider.java Tue Jul 17 11:35:23
2012
@@ -250,7 +250,7 @@ public class PreferredClassProvider exte
     private static String codebaseProperty = null;
     static {
 	String prop = AccessController.doPrivileged(
-   new GetPropertyAction("java.rmi.server.codebase"));
+           new GetPropertyAction("java.rmi.server.codebase"));
 	if (prop != null && prop.trim().length() > 0) {
 	    codebaseProperty = prop;
 	}
@@ -259,18 +259,26 @@ public class PreferredClassProvider exte
     /** table of "local" class loaders */
     private static final Map localLoaders =
 	Collections.synchronizedMap(new WeakHashMap());
-    static {
-	AccessController.doPrivileged(new PrivilegedAction() {
-	    public Object run() {
-		for (ClassLoader loader = ClassLoader.getSystemClassLoader();
-		     loader != null;
-		     loader = loader.getParent())
-		{
-		    localLoaders.put(loader, null);
-		}
-		return null;
-	    }
-	});
+    /** lazy load table of "local" class loaders to avoid java Policy 
+     * initialisation issues */
+    private static volatile boolean loaded = false;
+    static void load() {
+        if (loaded) return;
+        synchronized (localLoaders){
+            if (loaded) return; // Double checked
+            AccessController.doPrivileged(new PrivilegedAction() {
+                public Object run() {
+                    for (ClassLoader loader = ClassLoader.getSystemClassLoader();
+                         loader != null;
+                         loader = loader.getParent())
+                    {
+                        localLoaders.put(loader, null);
+                    }
+                    return null;
+                }
+            });
+            loaded = true;
+        }
     }
 
     /**
@@ -854,6 +862,7 @@ public class PreferredClassProvider exte
      * class loader
      */
     private static boolean isLocalLoader(ClassLoader loader) {
+        load();
 	return (loader == null || localLoaders.containsKey(loader));
     }
     



Mime
View raw message