![Jumploader](https://media.forgecdn.net/avatars/thumbnails/248/359/256/256/637168014265448801.png)
NullPointerException when natives mapping for libraries is incomplete
gharris1727 opened this issue ยท 4 comments
This manifests in the following stacktrace:
java.lang.NullPointerException
at link.infra.jumploader.resolution.sources.MinecraftJarSource.lambda$resolve$0(MinecraftJarSource.java:162)
at link.infra.jumploader.resolution.sources.MetadataCacheHelper$MetadataCacheView.lambda$getObject$1(MetadataCacheHelper.java:59)
at link.infra.jumploader.resolution.sources.MetadataCacheHelper$MetadataCacheView.lambda$getAsString$0(MetadataCacheHelper.java:55)
at link.infra.jumploader.resolution.sources.MetadataCacheHelper$MetadataCacheView.getAsBytes(MetadataCacheHelper.java:48)
at link.infra.jumploader.resolution.sources.MetadataCacheHelper$MetadataCacheView.getAsString(MetadataCacheHelper.java:55)
at link.infra.jumploader.resolution.sources.MetadataCacheHelper$MetadataCacheView.getObject(MetadataCacheHelper.java:59)
at link.infra.jumploader.resolution.sources.MinecraftJarSource.resolve(MinecraftJarSource.java:117)
at link.infra.jumploader.resolution.ResolutionProcessor.doMetaResolve(ResolutionProcessor.java:40)
at link.infra.jumploader.resolution.ResolutionProcessor.processMetadata(ResolutionProcessor.java:33)
at link.infra.jumploader.Jumploader.onLoad(Jumploader.java:100)
This was observed trying to load Minecraft 1.16.1 on OSX, and did not appear on Linux. I'm not sure at this time which library generated the error in particular. We were using the All Of Fabric 3 modpack with version 1.5.1. Jumploader 2.0.0 seems to have been in AoF3 since 1.4.0
Since at least Minecraft 1.12, the natives object only has mappings for OS names that are referenced in the rule set or classifiers. For example, 1.12.json includes this library definition:
{
"downloads": {
"artifact": {
"path": "ca/weblite/java-objc-bridge/1.0.0/java-objc-bridge-1.0.0.jar",
"sha1": "6ef160c3133a78de015830860197602ca1c855d3",
"size": 40502,
"url": "https://libraries.minecraft.net/ca/weblite/java-objc-bridge/1.0.0/java-objc-bridge-1.0.0.jar"
},
"classifiers": {
"javadoc": {
"path": "ca/weblite/java-objc-bridge/1.0.0/java-objc-bridge-1.0.0-javadoc.jar",
"sha1": "fb0092f22cb4fe8e631452f577b7a238778abf2a",
"size": 174060,
"url": "https://libraries.minecraft.net/ca/weblite/java-objc-bridge/1.0.0/java-objc-bridge-1.0.0-javadoc.jar"
},
"natives-osx": {
"path": "ca/weblite/java-objc-bridge/1.0.0/java-objc-bridge-1.0.0-natives-osx.jar",
"sha1": "08befab4894d55875f33c3d300f4f71e6e828f64",
"size": 5629,
"url": "https://libraries.minecraft.net/ca/weblite/java-objc-bridge/1.0.0/java-objc-bridge-1.0.0-natives-osx.jar"
},
"sources": {
"path": "ca/weblite/java-objc-bridge/1.0.0/java-objc-bridge-1.0.0-sources.jar",
"sha1": "865837a198189aee737019561ece842827f24278",
"size": 43283,
"url": "https://libraries.minecraft.net/ca/weblite/java-objc-bridge/1.0.0/java-objc-bridge-1.0.0-sources.jar"
}
}
},
"extract": {
"exclude": [
"META-INF/"
]
},
"name": "ca.weblite:java-objc-bridge:1.0.0",
"natives": {
"osx": "natives-osx"
},
"rules": [
{
"action": "allow",
"os": {
"name": "osx"
}
}
]
},
The line with the NPE in particular is where this natives object is queried for the current OS whenever the natives
object is defined:
However, if the object does not contain a mapping for the current OS (in the case of a partial mapping in >=1.12), this generates an NPE. Instead of an NPE, the launch should continue without the library; Since there is no mapping for the current OS, the library shouldn't be downloaded anyway.
Shouldn't the ruleset exclude libraries that don't have any native mappings for the current OS? If you can find which library causes this issue that'd be really helpful.
Thanks for the PR (I'll have another look through it tomorrow) although I might remove downloading natives entirely for now - due to https://github.com/comp500/Jumploader/wiki/Possible-future-changes-and-improvements#native-libraries Jumploader currently uses the native libraries supplied by the launcher anyway.
Shouldn't the ruleset exclude libraries that don't have any native mappings for the current OS?
It appears that some of the libraries are default-allow, and then specifically exclude OSX. I think this causes the rule checking to see the "allow everyone" rule and break early, before parsing the "disallow OSX" rule. One example I picked at random is lwjgl-stb
:
"name": "org.lwjgl:lwjgl-stb:3.2.2",
"natives": {
"linux": "natives-linux",
"windows": "natives-windows"
},
"rules": [
{
"action": "allow"
},
{
"action": "disallow",
"os": {
"name": "osx"
}
}
]
I found this (and 7 other libraries) with:
curl http://launchermeta.mojang.com/v1/packages/0c127f291db55d4a09830a3891c5447e63714d92/1.16.1.json | jq ".libraries|map(select(.natives and .natives.osx == null and .rules ))"
I think either one of these PRs would prevent the NPE, but perhaps fixing the rules engine is the "more correct" solution which addresses the problem instead of the symptom.
Rule evaluation happens in reverse, so that shouldn't cause an issue. I checked with a debugger, and the NPE actually seems to occur with the following library:
{
"downloads": {
"artifact": {
"path": "com/mojang/text2speech/1.11.3/text2speech-1.11.3.jar",
"sha1": "f378f889797edd7df8d32272c06ca80a1b6b0f58",
"size": 13164,
"url": "https://libraries.minecraft.net/com/mojang/text2speech/1.11.3/text2speech-1.11.3.jar"
},
"classifiers": {
"natives-linux": {
"path": "com/mojang/text2speech/1.11.3/text2speech-1.11.3-natives-linux.jar",
"sha1": "ac641755a2a841d1fca9e660194f42523ee5cfe0",
"size": 7833,
"url": "https://libraries.minecraft.net/com/mojang/text2speech/1.11.3/text2speech-1.11.3-natives-linux.jar"
},
"natives-windows": {
"path": "com/mojang/text2speech/1.11.3/text2speech-1.11.3-natives-windows.jar",
"sha1": "c0b242c0091be5acbf303263c7eeeaedd70544c7",
"size": 81379,
"url": "https://libraries.minecraft.net/com/mojang/text2speech/1.11.3/text2speech-1.11.3-natives-windows.jar"
},
"sources": {
"path": "com/mojang/text2speech/1.11.3/text2speech-1.11.3-sources.jar",
"sha1": "772a37dd77417571e6f119a8d306f0c14c2ee410",
"size": 5332,
"url": "https://libraries.minecraft.net/com/mojang/text2speech/1.11.3/text2speech-1.11.3-sources.jar"
}
}
},
"extract": {
"exclude": ["META-INF/"]
},
"name": "com.mojang:text2speech:1.11.3",
"natives": {
"linux": "natives-linux",
"windows": "natives-windows"
}
}
I'm still curious as to what the launcher does on macOS (I'll have a look at how MultiMC handles it) but it seems that your first PR would be the correct solution for this.