Skip to content

Commit

Permalink
Merge pull request #1690 from lilai23/fix_spi_2.1.x
Browse files Browse the repository at this point in the history
fix_2.1.x: classloaders in Sermant should not load implementations of SPI interface from parent classloader
  • Loading branch information
Sherlockhan authored Nov 30, 2024
2 parents 331fb06 + 84167c6 commit 949f104
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 949f104

Please sign in to comment.