Skip to content

Commit f7f977e

Browse files
authored
Merge pull request #741 from jtnord/debug
Pass through the remote `ClassLoader`’s name
2 parents 4280e21 + 98cc05c commit f7f977e

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/main/java/hudson/remoting/DumbClassLoaderBridge.java

+6
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,10 @@ public ResourceFile[] getResources2(String name) throws IOException {
7979
}
8080
return res;
8181
}
82+
83+
@Override
84+
public String getName() throws IOException {
85+
return base.getName();
86+
}
87+
8288
}

src/main/java/hudson/remoting/RemoteClassLoader.java

+32-3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.HashMap;
4545
import java.util.HashSet;
4646
import java.util.List;
47+
import java.util.Locale;
4748
import java.util.Map;
4849
import java.util.Set;
4950
import java.util.Vector;
@@ -170,11 +171,18 @@ public static ClassLoader create(@CheckForNull ClassLoader parent, @NonNull ICla
170171
// actually our classloader that we exported to the other side.
171172
return ((ClassLoaderProxy) proxy).cl;
172173
}
173-
return new RemoteClassLoader(parent, proxy);
174+
175+
String name;
176+
try {
177+
name = proxy.getName();
178+
} catch(IOException ignored) {
179+
name = String.format(Locale.ROOT, "unknown-due-to-io-error %1$#x", System.identityHashCode(proxy));
180+
}
181+
return new RemoteClassLoader(name, parent, proxy);
174182
}
175183

176-
private RemoteClassLoader(@CheckForNull ClassLoader parent, @NonNull IClassLoader proxy) {
177-
super(new URL[0], parent);
184+
private RemoteClassLoader(String name, @CheckForNull ClassLoader parent, @NonNull IClassLoader proxy) {
185+
super(name, new URL[0], parent);
178186
final Channel channel = RemoteInvocationHandler.unwrap(proxy);
179187
this.channel = channel == null ? null : channel.ref();
180188
this.underlyingProxy = proxy;
@@ -887,6 +895,12 @@ public interface IClassLoader {
887895
*/
888896
@NonNull
889897
ResourceFile[] getResources2(String name) throws IOException;
898+
899+
/**
900+
* Name of the classLoader
901+
* @since 3242
902+
*/
903+
String getName() throws IOException;
890904
}
891905

892906
/**
@@ -1178,6 +1192,11 @@ public ResourceFile[] getResources2(String name) throws IOException {
11781192
return r;
11791193
}
11801194

1195+
@Override
1196+
public String getName() throws IOException {
1197+
return cl.getName();
1198+
}
1199+
11811200
@Override
11821201
public boolean equals(Object that) {
11831202
if (this == that) {
@@ -1276,6 +1295,11 @@ public ResourceFile[] getResources2(String name) throws IOException {
12761295
return proxy.getResources2(name);
12771296
}
12781297

1298+
@Override
1299+
public String getName() throws IOException {
1300+
return proxy.getName();
1301+
}
1302+
12791303
private Object readResolve() throws ObjectStreamException {
12801304
try {
12811305
return getChannelForSerialization().getExportedObject(oid);
@@ -1336,6 +1360,11 @@ public ResourceFile[] getResources2(String name) throws IOException {
13361360
throw new IOException("Cannot get " + name, cause);
13371361
}
13381362

1363+
@Override
1364+
public String getName() throws IOException {
1365+
throw new IOException("Cannot getName", cause);
1366+
}
1367+
13391368
}
13401369

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

0 commit comments

Comments
 (0)