diff --git a/src/main/java/org/quiltmc/loader/impl/filesystem/DelegatingUrlStreamHandlerFactory.java b/src/main/java/org/quiltmc/loader/impl/filesystem/DelegatingUrlStreamHandlerFactory.java index d9c8df752..7ba0f9b96 100644 --- a/src/main/java/org/quiltmc/loader/impl/filesystem/DelegatingUrlStreamHandlerFactory.java +++ b/src/main/java/org/quiltmc/loader/impl/filesystem/DelegatingUrlStreamHandlerFactory.java @@ -22,6 +22,7 @@ import org.quiltmc.loader.impl.util.QuiltLoaderInternal; import org.quiltmc.loader.impl.util.QuiltLoaderInternalType; +import org.quiltmc.loader.impl.util.SystemProperties; /** Holds the {@link URLStreamHandlerFactory} for all quilt filesystems. This is set to * {@link URL#setURLStreamHandlerFactory(URLStreamHandlerFactory)}. @@ -32,11 +33,15 @@ public class DelegatingUrlStreamHandlerFactory implements URLStreamHandlerFactory { public static final DelegatingUrlStreamHandlerFactory INSTANCE = new DelegatingUrlStreamHandlerFactory(); + private static final boolean DISABLED; private URLStreamHandlerFactory[] factories = new URLStreamHandlerFactory[0]; static { - URL.setURLStreamHandlerFactory(INSTANCE); + DISABLED = Boolean.getBoolean(SystemProperties.DISABLE_URL_STREAM_FACTORY); + if (!DISABLED) { + URL.setURLStreamHandlerFactory(INSTANCE); + } } static void load() { @@ -44,6 +49,12 @@ static void load() { } public static synchronized void appendFactory(URLStreamHandlerFactory factory) { + if (DISABLED) { + throw new Error( + "The system property '" + SystemProperties.DISABLE_URL_STREAM_FACTORY + + "' has been set to true, which disables custom factories - you will need to reconfigure your environment!" + ); + } URLStreamHandlerFactory[] copy = new URLStreamHandlerFactory[INSTANCE.factories.length + 1]; System.arraycopy(INSTANCE.factories, 0, copy, 0, INSTANCE.factories.length); copy[INSTANCE.factories.length] = factory; diff --git a/src/main/java/org/quiltmc/loader/impl/util/SystemProperties.java b/src/main/java/org/quiltmc/loader/impl/util/SystemProperties.java index d1ac708c5..538430fc1 100644 --- a/src/main/java/org/quiltmc/loader/impl/util/SystemProperties.java +++ b/src/main/java/org/quiltmc/loader/impl/util/SystemProperties.java @@ -17,6 +17,9 @@ package org.quiltmc.loader.impl.util; +import java.net.URL; +import java.net.URLStreamHandlerFactory; + import org.quiltmc.loader.impl.filesystem.QuiltBasePath; import org.quiltmc.loader.impl.filesystem.QuiltClassPath; import org.quiltmc.loader.impl.filesystem.QuiltMapFileSystem; @@ -96,6 +99,10 @@ private SystemProperties() {} public static final String DISABLE_QUILT_CLASS_PATH_CUSTOM_TABLE = "loader.quilt_class_path.disable_custom_table"; public static final String DISABLE_BUILTIN_MIXIN_EXTRAS = "loader.disable_builtin_mixin_extras"; + /** Disables loader from registering its {@link URLStreamHandlerFactory} with + * {@link URL#setURLStreamHandlerFactory(URLStreamHandlerFactory)}. This */ + public static final String DISABLE_URL_STREAM_FACTORY = "loader.disable_url_stream_factory"; + // ############## // # Validation # // ##############