介绍
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.
常见问题
Unsafe Service Loader Inspector 支持哪些 Minecraft 版本?
Unsafe Service Loader Inspector 支持 Minecraft Java 版 1.21.1,可用的加载器:NeoForge。下载时注意选择和你游戏版本一致的文件。
Unsafe Service Loader Inspector 怎么安装?
先用 PCL2 或 HMCL 启动器安装对应版本的 NeoForge,再把下载的 .jar 文件放进游戏目录的 mods 文件夹,重新启动游戏即可。开启了版本隔离的,mods 文件夹在 versions/版本名 下面。
Partonetrain 的其他作品
查看全部 →夸克 Quark
夸克是一种非常微小的东西。这个模组是一系列小玩意的集合……
Zeta
模块化模组的综合支撑前置库
Mana Gear
将植物魔法中的金属用于 Silent Gear
Dragon Gear
在 Silent Gear 中使用 Ice and Fire 的材料!
评论
登录后评论和评分