mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-31 21:52:59 +00:00 
			
		
		
		
	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:
		| @@ -29,7 +29,7 @@ public final class 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()); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jonathan Coates
					Jonathan Coates