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 26, 2024
1 parent 9f81370 commit 7581c63
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import io.sermant.core.common.CommonConstant;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -118,4 +120,15 @@ public URL getResource(String name) {
public void addURL(URL url) {
super.addURL(url);
}

@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);
}
}

0 comments on commit 7581c63

Please sign in to comment.