Skip to content

Commit

Permalink
Add a system property to disable DelegatingUrlStreamHandlerFactory.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexIIL committed Apr 21, 2024
1 parent 2f6b816 commit ea966d3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)}.
Expand All @@ -32,18 +33,28 @@
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() {
// Just calls <clinit>
}

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 #
// ##############
Expand Down

0 comments on commit ea966d3

Please sign in to comment.