Load services with the service's classloader
We were seeing some strange issues in the Fabric test code where we tried to load the implementation from a different classloader. This ensures that the classloaders are consistent.
This commit is contained in:
parent
cef4b4906b
commit
0abd107348
|
@ -29,7 +29,7 @@ private Services() {
|
|||
* @throws IllegalStateException When the service cannot be loaded.
|
||||
*/
|
||||
public static <T> T load(Class<T> klass) {
|
||||
var services = ServiceLoader.load(klass).stream().toList();
|
||||
var services = ServiceLoader.load(klass, klass.getClassLoader()).stream().toList();
|
||||
return switch (services.size()) {
|
||||
case 1 -> services.get(0).get();
|
||||
case 0 -> throw new IllegalStateException("Cannot find service for " + klass.getName());
|
||||
|
|
Loading…
Reference in New Issue