From ad8d7d78e35b006cbf3fdb55459809808bb397c0 Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Sat, 16 Dec 2023 12:50:18 +0100 Subject: [PATCH] Allow ModuleClassLoader to delegate class-loading to parent for unit testing without class-loader isolation. --- src/main/java/cpw/mods/cl/ModuleClassLoader.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/cpw/mods/cl/ModuleClassLoader.java b/src/main/java/cpw/mods/cl/ModuleClassLoader.java index 6a47ed2..1de1398 100644 --- a/src/main/java/cpw/mods/cl/ModuleClassLoader.java +++ b/src/main/java/cpw/mods/cl/ModuleClassLoader.java @@ -1,6 +1,7 @@ package cpw.mods.cl; import cpw.mods.util.LambdaExceptionUtils; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.io.InputStream; @@ -64,10 +65,15 @@ private static void bindToLayer(ModuleClassLoader classLoader, ModuleLayer layer private final Map resolvedRoots; private final Map packageLookup; private final Map parentLoaders; - private ClassLoader fallbackClassLoader = ClassLoader.getPlatformClassLoader(); + private ClassLoader fallbackClassLoader; public ModuleClassLoader(final String name, final Configuration configuration, final List parentLayers) { - super(name, null); + this(name, configuration, parentLayers, null); + } + + public ModuleClassLoader(final String name, final Configuration configuration, final List parentLayers, @Nullable ClassLoader parentLoader) { + super(name, parentLoader); + this.fallbackClassLoader = Objects.requireNonNullElse(parentLoader, ClassLoader.getPlatformClassLoader()); this.configuration = configuration; this.packageLookup = new HashMap<>(); this.resolvedRoots = configuration.modules().stream()