From df69f1f344187db0d62354d30cb8a584ed89c67e Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sat, 26 Oct 2024 18:55:22 +0200 Subject: [PATCH] Fix InformativeException value shuffling --- .../exception/InformativeException.java | 18 +++++++++++------- .../protocol/packet/PacketWrapperImpl.java | 6 +++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/exception/InformativeException.java b/api/src/main/java/com/viaversion/viaversion/exception/InformativeException.java index 820d4762d..d2cb0e139 100644 --- a/api/src/main/java/com/viaversion/viaversion/exception/InformativeException.java +++ b/api/src/main/java/com/viaversion/viaversion/exception/InformativeException.java @@ -22,11 +22,12 @@ */ package com.viaversion.viaversion.exception; -import java.util.HashMap; -import java.util.Map; +import java.util.ArrayList; +import java.util.List; +import org.checkerframework.checker.nullness.qual.Nullable; public class InformativeException extends RuntimeException { - private final Map info = new HashMap<>(); + private final List dataEntries = new ArrayList<>(); private boolean shouldBePrinted = true; private int sources; @@ -34,8 +35,8 @@ public class InformativeException extends RuntimeException { super(cause); } - public InformativeException set(String key, Object value) { - info.put(key, value); + public InformativeException set(String key, @Nullable Object value) { + dataEntries.add(new DataEntry(key, value)); return this; } @@ -59,11 +60,11 @@ public class InformativeException extends RuntimeException { public String getMessage() { StringBuilder builder = new StringBuilder("Please report this on the Via support Discord or open an issue on the relevant GitHub repository\n"); boolean first = true; - for (Map.Entry entry : info.entrySet()) { + for (DataEntry entry : dataEntries) { if (!first) { builder.append(", "); } - builder.append(entry.getKey()).append(": ").append(entry.getValue()); + builder.append(entry.name()).append(": ").append(entry.value()); first = false; } return builder.toString(); @@ -74,4 +75,7 @@ public class InformativeException extends RuntimeException { // Don't record this stack return this; } + + private record DataEntry(String name, @Nullable Object value) { + } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocol/packet/PacketWrapperImpl.java b/common/src/main/java/com/viaversion/viaversion/protocol/packet/PacketWrapperImpl.java index ca562eb41..9f05ef28c 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocol/packet/PacketWrapperImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/protocol/packet/PacketWrapperImpl.java @@ -243,11 +243,11 @@ public class PacketWrapperImpl implements PacketWrapper { private InformativeException createInformativeException(final Exception cause, final Type type, final int index) { return new InformativeException(cause) + .set("Packet Type", this.packetType) .set("Index", index) .set("Type", type.getTypeName()) - .set("Packet ID", this.id) - .set("Packet Type", this.packetType) - .set("Data", this.packetValues); + .set("Data", this.packetValues) + .set("Packet ID", this.id); } @Override