From 0abd1073486501215cca5a4bf47e3005eb7509c1 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Thu, 21 Mar 2024 20:50:31 +0000 Subject: [PATCH] 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. --- .../src/main/java/dan200/computercraft/impl/Services.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/common-api/src/main/java/dan200/computercraft/impl/Services.java b/projects/common-api/src/main/java/dan200/computercraft/impl/Services.java index f37dee354..10f9c1a1d 100644 --- a/projects/common-api/src/main/java/dan200/computercraft/impl/Services.java +++ b/projects/common-api/src/main/java/dan200/computercraft/impl/Services.java @@ -29,7 +29,7 @@ public final class Services { * @throws IllegalStateException When the service cannot be loaded. */ public static T load(Class 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());