Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass through the remote ClassLoader’s name #741

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assumes this will be the next thing released

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think we bother with @since in CD-versioned components, though it is possible.

*/
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