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:
Jonathan Coates 2024-03-21 20:50:31 +00:00
parent cef4b4906b
commit 0abd107348
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
1 changed files with 1 additions and 1 deletions

View File

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