From 84167c6c07dbc5b70860fdc858279c10294c6fde Mon Sep 17 00:00:00 2001 From: lilai Date: Tue, 26 Nov 2024 16:10:04 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90fix=E3=80=91classloaders=20in=20Serman?= =?UTF-8?q?t=20should=20not=20load=20implementations=20of=20SPI=20interfac?= =?UTF-8?q?e=20from=20parent=20classloader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lilai --- .../core/plugin/classloader/PluginClassLoader.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/classloader/PluginClassLoader.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/classloader/PluginClassLoader.java index 6c74d00c77..368ddcd191 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/classloader/PluginClassLoader.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/classloader/PluginClassLoader.java @@ -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; @@ -150,6 +152,17 @@ private Class getClassFromLocalClassLoader(String name) { return clazz; } + @Override + public Enumeration 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