From 2fe96e443567dbf503d060d480e842c7aed2e6fb Mon Sep 17 00:00:00 2001 From: Henry Le Grys Date: Wed, 27 Apr 2022 02:02:47 +0100 Subject: [PATCH] Fix NPE when manifests don't contain JVM arguments Jackson upgrade exposed/introduced a bug where the JVM half of Minecraft arguments could end up missing in some cases. Not exactly sure if the field was null on the serializing side or just an empty array, but we just fix it by always initializing the fields. --- .../com/skcraft/launcher/model/loader/VersionInfo.java | 2 -- .../launcher/model/minecraft/MinecraftArguments.java | 5 +++-- .../skcraft/launcher/model/minecraft/VersionManifest.java | 7 ++++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/launcher/src/main/java/com/skcraft/launcher/model/loader/VersionInfo.java b/launcher/src/main/java/com/skcraft/launcher/model/loader/VersionInfo.java index 7d383bcd0..6b52672a6 100644 --- a/launcher/src/main/java/com/skcraft/launcher/model/loader/VersionInfo.java +++ b/launcher/src/main/java/com/skcraft/launcher/model/loader/VersionInfo.java @@ -14,7 +14,6 @@ import com.skcraft.launcher.model.minecraft.MinecraftArguments; import lombok.Data; -import java.util.ArrayList; import java.util.List; @Data @@ -29,7 +28,6 @@ public class VersionInfo { public void setMinecraftArguments(String argumentString) { MinecraftArguments minecraftArguments = new MinecraftArguments(); - minecraftArguments.setGameArguments(new ArrayList()); for (String arg : Splitter.on(' ').split(argumentString)) { minecraftArguments.getGameArguments().add(new GameArgument(arg)); diff --git a/launcher/src/main/java/com/skcraft/launcher/model/minecraft/MinecraftArguments.java b/launcher/src/main/java/com/skcraft/launcher/model/minecraft/MinecraftArguments.java index 801e2d244..077f7a4f1 100644 --- a/launcher/src/main/java/com/skcraft/launcher/model/minecraft/MinecraftArguments.java +++ b/launcher/src/main/java/com/skcraft/launcher/model/minecraft/MinecraftArguments.java @@ -9,6 +9,7 @@ import com.skcraft.launcher.model.minecraft.mapper.MinecraftArgumentsSerializer; import lombok.Data; +import java.util.ArrayList; import java.util.List; @Data @@ -18,12 +19,12 @@ public class MinecraftArguments { @JsonTypeInfo(use = JsonTypeInfo.Id.NONE) @JsonSerialize(contentUsing = MinecraftArgumentsSerializer.class) @JsonDeserialize(contentUsing = MinecraftArgumentsDeserializer.class) - private List gameArguments; + private List gameArguments = new ArrayList<>(); @JsonProperty("jvm") @JsonTypeInfo(use = JsonTypeInfo.Id.NONE) @JsonSerialize(contentUsing = MinecraftArgumentsSerializer.class) @JsonDeserialize(contentUsing = MinecraftArgumentsDeserializer.class) - private List jvmArguments; + private List jvmArguments = new ArrayList<>(); } diff --git a/launcher/src/main/java/com/skcraft/launcher/model/minecraft/VersionManifest.java b/launcher/src/main/java/com/skcraft/launcher/model/minecraft/VersionManifest.java index dd3cf63c6..f1ffa2e98 100644 --- a/launcher/src/main/java/com/skcraft/launcher/model/minecraft/VersionManifest.java +++ b/launcher/src/main/java/com/skcraft/launcher/model/minecraft/VersionManifest.java @@ -12,7 +12,10 @@ import com.skcraft.launcher.model.loader.SidedData; import lombok.Data; -import java.util.*; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.Map; @Data @JsonIgnoreProperties(ignoreUnknown = true) @@ -50,8 +53,6 @@ public Library findLibrary(String name) { public void setMinecraftArguments(String minecraftArguments) { MinecraftArguments result = new MinecraftArguments(); - result.setGameArguments(new ArrayList()); - result.setJvmArguments(new ArrayList()); for (String arg : Splitter.on(' ').split(minecraftArguments)) { result.getGameArguments().add(new GameArgument(arg));