Skip to content

Commit 949f104

Browse files
authored
Merge pull request #1690 from lilai23/fix_spi_2.1.x
fix_2.1.x: classloaders in Sermant should not load implementations of SPI interface from parent classloader
2 parents 331fb06 + 84167c6 commit 949f104

File tree

1 file changed

+13
-0
lines changed
  • sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/classloader

1 file changed

+13
-0
lines changed

Diff for: sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/classloader/PluginClassLoader.java

+13
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
import io.sermant.core.config.ConfigManager;
2121
import io.sermant.core.plugin.agent.config.AgentConfig;
2222

23+
import java.io.IOException;
2324
import java.net.URL;
2425
import java.net.URLClassLoader;
26+
import java.util.Enumeration;
2527
import java.util.HashMap;
2628
import java.util.Map;
2729
import java.util.logging.Level;
@@ -150,6 +152,17 @@ private Class<?> getClassFromLocalClassLoader(String name) {
150152
return clazz;
151153
}
152154

155+
@Override
156+
public Enumeration<URL> getResources(String name) throws IOException {
157+
// Due to class isolation, the service loader does not obtain the service provider from the parent
158+
// classloader, but returns only the resources in current classloader
159+
if (name.startsWith("META-INF/services/")) {
160+
return findResources(name);
161+
}
162+
163+
return super.getResources(name);
164+
}
165+
153166
/**
154167
* Load classes only through Sermant's own search path, not using localClassLoader, which would otherwise cause
155168
* stackoverflow

0 commit comments

Comments
 (0)