Skip to content
Permalink
Browse files

[JENKINS-37566] - DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED i Remote…

…ClassLoader
  • Loading branch information...
oleg-nenashev committed Oct 7, 2016
1 parent 755473f commit a185cb2aca2c4f47505347420cf979193aca4cee
Showing with 38 additions and 7 deletions.
  1. +38 −7 src/main/java/hudson/remoting/RemoteClassLoader.java
@@ -33,6 +33,7 @@
import java.net.MalformedURLException;
import java.net.URLClassLoader;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Enumeration;
import java.util.HashMap;
@@ -108,14 +109,29 @@
*/
private final Map<String,ClassReference> prefetchedClasses = Collections.synchronizedMap(new HashMap<String,ClassReference>());

public static ClassLoader create(ClassLoader parent, IClassLoader proxy) {
public static ClassLoader create(final ClassLoader parent, final IClassLoader proxy) {
if(proxy instanceof ClassLoaderProxy) {
// when the remote sends 'RemoteIClassLoader' as the proxy, on this side we get it
// as ClassLoaderProxy. This means, the so-called remote classloader here is
// actually our classloader that we exported to the other side.
return ((ClassLoaderProxy)proxy).cl;
}
return new RemoteClassLoader(parent, proxy);

// Create new RemoteClassLoader otherwise
final RemoteClassLoader created;
try {
created = AccessController.doPrivileged(
new PrivilegedExceptionAction<RemoteClassLoader>() {
@Override
public RemoteClassLoader run() throws Exception {
return new RemoteClassLoader(parent, proxy);
}
});
} catch (PrivilegedActionException ex) {
LOGGER.log(SEVERE, "Cannot instantiate the Remote classloader", ex);
throw new IllegalStateException( "Cannot instantiate the Remote classloader", ex);
}
return created;
}

private RemoteClassLoader(ClassLoader parent, IClassLoader proxy) {
@@ -996,12 +1012,27 @@ public String toString() {
* any new classpath. In this way, we can effectively use this classloader as a representation
* of the bootstrap classloader.
*/
private static final ClassLoader PSEUDO_BOOTSTRAP = new URLClassLoader(new URL[0],(ClassLoader)null) {
@Override
public String toString() {
return "PSEUDO_BOOTSTRAP";
private static final ClassLoader PSEUDO_BOOTSTRAP;

static {
try {
PSEUDO_BOOTSTRAP = AccessController.doPrivileged(
new PrivilegedExceptionAction<ClassLoader>() {
@Override
public ClassLoader run() throws Exception {
return new URLClassLoader(new URL[0],(ClassLoader)null) {
@Override
public String toString() {
return "PSEUDO_BOOTSTRAP";
}
};
}
});
} catch (PrivilegedActionException ex) {
LOGGER.log(SEVERE, "Cannot instantiate the Pseudo Bootstrap classloader", ex);
throw new IllegalStateException( "Cannot instantiate the Pseudo Bootstrap classloader", ex);
}
};
}
}

/**

0 comments on commit a185cb2

Please sign in to comment.
You can’t perform that action at this time.