Skip to content

Commit

Permalink
Merge pull request #741 from jtnord/debug
Browse files Browse the repository at this point in the history
Pass through the remote `ClassLoader`’s name
  • Loading branch information
jtnord authored May 15, 2024
2 parents 4280e21 + 98cc05c commit f7f977e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/main/java/hudson/remoting/DumbClassLoaderBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,10 @@ public ResourceFile[] getResources2(String name) throws IOException {
}
return res;
}

@Override
public String getName() throws IOException {
return base.getName();
}

}
35 changes: 32 additions & 3 deletions src/main/java/hudson/remoting/RemoteClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
Expand Down Expand Up @@ -170,11 +171,18 @@ public static ClassLoader create(@CheckForNull ClassLoader parent, @NonNull ICla
// actually our classloader that we exported to the other side.
return ((ClassLoaderProxy) proxy).cl;
}
return new RemoteClassLoader(parent, proxy);

String name;
try {
name = proxy.getName();
} catch(IOException ignored) {
name = String.format(Locale.ROOT, "unknown-due-to-io-error %1$#x", System.identityHashCode(proxy));
}
return new RemoteClassLoader(name, parent, proxy);
}

private RemoteClassLoader(@CheckForNull ClassLoader parent, @NonNull IClassLoader proxy) {
super(new URL[0], parent);
private RemoteClassLoader(String name, @CheckForNull ClassLoader parent, @NonNull IClassLoader proxy) {
super(name, new URL[0], parent);
final Channel channel = RemoteInvocationHandler.unwrap(proxy);
this.channel = channel == null ? null : channel.ref();
this.underlyingProxy = proxy;
Expand Down Expand Up @@ -887,6 +895,12 @@ public interface IClassLoader {
*/
@NonNull
ResourceFile[] getResources2(String name) throws IOException;

/**
* Name of the classLoader
* @since 3242
*/
String getName() throws IOException;
}

/**
Expand Down Expand Up @@ -1178,6 +1192,11 @@ public ResourceFile[] getResources2(String name) throws IOException {
return r;
}

@Override
public String getName() throws IOException {
return cl.getName();
}

@Override
public boolean equals(Object that) {
if (this == that) {
Expand Down Expand Up @@ -1276,6 +1295,11 @@ public ResourceFile[] getResources2(String name) throws IOException {
return proxy.getResources2(name);
}

@Override
public String getName() throws IOException {
return proxy.getName();
}

private Object readResolve() throws ObjectStreamException {
try {
return getChannelForSerialization().getExportedObject(oid);
Expand Down Expand Up @@ -1336,6 +1360,11 @@ public ResourceFile[] getResources2(String name) throws IOException {
throw new IOException("Cannot get " + name, cause);
}

@Override
public String getName() throws IOException {
throw new IOException("Cannot getName", cause);
}

}

private static Iterable<String> analyze(InputStream bytecode) {
Expand Down

0 comments on commit f7f977e

Please sign in to comment.