Skip to content

Commit

Permalink
【fix】classloaders in Sermant should not load implementations of SPI i…
Browse files Browse the repository at this point in the history
…nterface from parent classloader

Signed-off-by: lilai <[email protected]>
  • Loading branch information
lilai23 committed Nov 29, 2024
1 parent 331fb06 commit 84167c6
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import io.sermant.core.config.ConfigManager;
import io.sermant.core.plugin.agent.config.AgentConfig;

import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
Expand Down Expand Up @@ -150,6 +152,17 @@ private Class<?> getClassFromLocalClassLoader(String name) {
return clazz;
}

@Override
public Enumeration<URL> getResources(String name) throws IOException {
// Due to class isolation, the service loader does not obtain the service provider from the parent
// classloader, but returns only the resources in current classloader
if (name.startsWith("META-INF/services/")) {
return findResources(name);
}

return super.getResources(name);
}

/**
* Load classes only through Sermant's own search path, not using localClassLoader, which would otherwise cause
* stackoverflow
Expand Down

0 comments on commit 84167c6

Please sign in to comment.