UnsafeServiceLoaderInspector
If you're not having duplicate registration crashes, you probably don't need this mod.
This mod attempts to find and log calls to the single-argument version of ServiceLoader#load, which may be unsafe and can effectively cause the game to try to boot up in a ruined state.
Unfortunately, this outcome is rather difficult to reproduce because:
- it depends on your modlist
- it's a race condition
- it's machine dependent because by default neoforge mod init is multithreaded based on number of cores
- mod load order is a factor
Still, it's an issue because it can lead to different types of difficult-to-debug crashes, most commonly duplicate registration errors. Unfortunately, a lot of mods have or did have this problem (including my own!), often because the mods were forked from an old version of Jared's multiloader template that had the issue.
Usage
Once installed, search in your log for: Single-arg ServiceLoader#load call detected!!! The mod will print the offending jar as well as the class. It will look something like this:
[ServiceLoaderInspector] Single-arg ServiceLoader#load call detected!!!
Mod/JAR: trains_tweaks-neoforge-1.21.1-0.9.21.jar
Class: info.partonetrain.trains_tweaks.platform.Services
Source: Services.java
Method: load(Ljava/lang/Class;)Ljava/lang/Object;
Line: 24
Invocation: java.util.ServiceLoader.load(Ljava/lang/Class;)Ljava/util/ServiceLoader;
Do note that calls to this method are not intrinsically unsafe, so further investigation is required, but this mod can be a starting point for debugging duplicate registration errors.
Mitigation
Unsafe ServiceLoader#load calls may be able to be worked around by changing the following option in your instance's config/fml.toml to 1.
However, this obviously increases load times. If this doesn't work, then it's due to the mod load order, which can also be worked around with dependency overrides in the same file (but unfortunately you'll have to figure that out for your modpack on your own).
#Max threads for early initialization parallelism, -1 is based on processor count
maxThreads = 1
However, I believe it would just be better for everyone if all instances of this issue were found and fixed.
Full Disclosure: AI use
The main functionality of this mod (most of the methods in the ServiceLoaderInspector class) were created with the assistance of ChatGPT.
After a weekslong attempt at trying to debug a duplicate registration crash (which included an attempt at writing a python script that does something similar that this does) in my modpack, I caved and "asked" ChatGPT for Java code capable of detecting the root issue (single-arg ServiceLoader#load calls) in mod jars.
After verifying the output by cross-referencing mods' source code, I put that code in this mod.

