From 30b0b0572f31324370609590d89d449ef4b8b9c9 Mon Sep 17 00:00:00 2001 From: Overlord Date: Thu, 1 Oct 2026 18:05:32 +0200 Subject: [PATCH] Annotate with `@SuppressWarnings("NullableProblems")`, clean up imports, and adjust nullability annotations for improved clarity and consistency. --- .../zomboidforge/patcher/ClassPatch.java | 1 + .../zomboidforge/patcher/JarPatcher.java | 26 ++++++------------- .../patcher/Patches/HookInjectionPatch.java | 5 ++-- .../patcher/Patches/PerformancePatch.java | 6 ++--- 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/patcher/src/main/java/dev/overlord/zomboidforge/patcher/ClassPatch.java b/patcher/src/main/java/dev/overlord/zomboidforge/patcher/ClassPatch.java index a07cc86..b9ca16a 100644 --- a/patcher/src/main/java/dev/overlord/zomboidforge/patcher/ClassPatch.java +++ b/patcher/src/main/java/dev/overlord/zomboidforge/patcher/ClassPatch.java @@ -7,6 +7,7 @@ import org.objectweb.asm.tree.ClassNode; /** A build-time change to one class of the vanilla server jar. */ @Internal +@SuppressWarnings("NullableProblems") public interface ClassPatch { /** Internal name of the class to patch, e.g. {@code zombie/network/GameServer}. */ String target(); diff --git a/patcher/src/main/java/dev/overlord/zomboidforge/patcher/JarPatcher.java b/patcher/src/main/java/dev/overlord/zomboidforge/patcher/JarPatcher.java index 01212d2..183306a 100644 --- a/patcher/src/main/java/dev/overlord/zomboidforge/patcher/JarPatcher.java +++ b/patcher/src/main/java/dev/overlord/zomboidforge/patcher/JarPatcher.java @@ -1,5 +1,7 @@ package dev.overlord.zomboidforge.patcher; +import org.jetbrains.annotations.Nullable; + import org.objectweb.asm.ClassReader; import org.objectweb.asm.tree.ClassNode; @@ -7,15 +9,7 @@ import java.io.IOException; import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Enumeration; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.ServiceLoader; -import java.util.Set; -import java.util.TreeSet; +import java.util.*; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; @@ -84,7 +78,7 @@ public final class JarPatcher { try (ZipFile zip = new ZipFile(jar.toFile())) { - byte[] core = read(zip, GameVersionReader.CORE_CLASS + ".class"); + byte[] core = JarPatcher.read(zip, GameVersionReader.CORE_CLASS + ".class"); if (core == null) throw new IllegalStateException("'" + jar + "' contains no " + GameVersionReader.CORE_CLASS + ".class"); return GameVersionReader.read(core); @@ -104,12 +98,8 @@ public final class JarPatcher */ public static List applicablePatches(PatchSet patchSet, GameVersion version, Set disabled) { - if (patchSet.build() != version.major()) { - throw new IllegalStateException( - "Patch set is for Build " + patchSet.build() - + ", but the server jar is Project Zomboid " + version - ); - } + if (patchSet.build() != version.major()) + throw new IllegalStateException("Patch set is for Build " + patchSet.build() + ", but the server jar is Project Zomboid " + version + "."); Set unknown = new TreeSet<>(disabled); patchSet.patches().forEach(patch -> unknown.remove(patch.getClass().getSimpleName())); @@ -218,7 +208,7 @@ public final class JarPatcher patch.apply(node); } - HierarchyClassWriter writer = new HierarchyClassWriter(name -> read(jar, name + ".class")); + HierarchyClassWriter writer = new HierarchyClassWriter(name -> Objects.requireNonNull(JarPatcher.read(jar, name + ".class"))); node.accept(writer); return writer.toByteArray(); @@ -230,7 +220,7 @@ public final class JarPatcher catch (IllegalStateException e) { throw new IllegalStateException("'" + patch.getClass().getSimpleName() + "': " + e.getMessage(), e); } } - private static byte[] read(ZipFile jar, String entryName) + private static byte @Nullable [] read(ZipFile jar, String entryName) { ZipEntry entry = jar.getEntry(entryName); if (entry == null) return null; diff --git a/patcher/src/main/java/dev/overlord/zomboidforge/patcher/Patches/HookInjectionPatch.java b/patcher/src/main/java/dev/overlord/zomboidforge/patcher/Patches/HookInjectionPatch.java index 2612601..b344017 100644 --- a/patcher/src/main/java/dev/overlord/zomboidforge/patcher/Patches/HookInjectionPatch.java +++ b/patcher/src/main/java/dev/overlord/zomboidforge/patcher/Patches/HookInjectionPatch.java @@ -3,7 +3,6 @@ package dev.overlord.zomboidforge.patcher.Patches; import dev.overlord.zomboidforge.patcher.Anchor; import dev.overlord.zomboidforge.patcher.ClassPatch; import dev.overlord.zomboidforge.patcher.Hook; -import org.jetbrains.annotations.NotNull; import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.ClassNode; @@ -24,7 +23,7 @@ public abstract class HookInjectionPatch implements ClassPatch private final Anchor.Call anchor; private final Hook hook; - protected HookInjectionPatch(String target, Anchor.Call anchor, @NotNull Hook hook) + protected HookInjectionPatch(String target, Anchor.Call anchor, Hook hook) { if (!hook.desc().equals(HookInjectionPatch.HOOK_DESC)) throw new IllegalArgumentException("Hook '" + hook + "' must have descriptor '" + HookInjectionPatch.HOOK_DESC + "'."); @@ -39,7 +38,7 @@ public abstract class HookInjectionPatch implements ClassPatch @Override public final Anchor.Call anchor() { return this.anchor; } @Override - public final @NotNull Hook hook() { return this.hook; } + public final Hook hook() { return this.hook; } @Override public final void apply(ClassNode node) diff --git a/patcher/src/main/java/dev/overlord/zomboidforge/patcher/Patches/PerformancePatch.java b/patcher/src/main/java/dev/overlord/zomboidforge/patcher/Patches/PerformancePatch.java index 98d8e8e..7f15030 100644 --- a/patcher/src/main/java/dev/overlord/zomboidforge/patcher/Patches/PerformancePatch.java +++ b/patcher/src/main/java/dev/overlord/zomboidforge/patcher/Patches/PerformancePatch.java @@ -4,7 +4,7 @@ import dev.overlord.zomboidforge.patcher.Anchor; import dev.overlord.zomboidforge.patcher.ClassPatch; import dev.overlord.zomboidforge.patcher.GameVersion; import dev.overlord.zomboidforge.patcher.Hook; -import org.jetbrains.annotations.NotNull; + import org.jetbrains.annotations.Nullable; import org.objectweb.asm.tree.ClassNode; @@ -24,13 +24,13 @@ public abstract class PerformancePatch implements ClassPatch { private final String target; private final Anchor anchor; - private final Hook hook; + private final @Nullable Hook hook; /** * @param hook the runtime method the patched code calls, or {@code null} when the patch * only changes the target class itself */ - protected PerformancePatch(String target, @NotNull Anchor anchor, @Nullable Hook hook) + protected PerformancePatch(String target, Anchor anchor, @Nullable Hook hook) { this.target = Objects.requireNonNull(target); this.anchor = Objects.requireNonNull(anchor);