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

Load agent classes child first #5950

Merged
merged 1 commit into from
Apr 28, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,25 @@ public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundExce
throw new ClassNotFoundException(name);
}

return super.loadClass(name, resolve);
synchronized (getClassLoadingLock(name)) {
Class<?> clazz = findLoadedClass(name);
// first search agent classes
if (clazz == null) {
clazz = findAgentClass(name);
}
// search from parent and urls added to this loader
if (clazz == null) {
clazz = super.loadClass(name, false);
}
if (resolve) {
resolveClass(clazz);
}

return clazz;
}
}

@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
private Class<?> findAgentClass(String name) throws ClassNotFoundException {
JarEntry jarEntry = findJarEntry(name.replace('.', '/') + ".class");
if (jarEntry != null) {
byte[] bytes;
Expand All @@ -156,8 +170,7 @@ protected Class<?> findClass(String name) throws ClassNotFoundException {
return defineClass(name, bytes);
}

// find class from agent initializer jar
return super.findClass(name);
return null;
}

public Class<?> defineClass(String name, byte[] bytes) {
Expand Down Expand Up @@ -281,7 +294,7 @@ private URL getJarEntryUrl(JarEntry jarEntry) {
public Enumeration<URL> findResources(String name) throws IOException {
// find resources from agent initializer jar
Enumeration<URL> delegate = super.findResources(name);
// agent jar can have only once resource for given name
// agent jar can have only one resource for given name
URL url = findJarResource(name);
if (url != null) {
return new Enumeration<URL>() {
Expand Down