2021-06-21 08:09:18 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
Date: Sun, 20 Jun 2021 18:19:09 -0700
2021-06-22 04:12:07 +00:00
Subject: [PATCH] Deobfuscate stacktraces in log messages, crash reports, and
etc.
2021-06-21 08:09:18 +00:00
diff --git a/build.gradle.kts b/build.gradle.kts
2024-04-23 19:23:27 +00:00
index 4eec2a9aace7bca8383c893eedf0c27e06ba71c6..4e24a9dcad6c8b3f52c3039f2ba80dfedb911e03 100644
2021-06-21 08:09:18 +00:00
--- a/build.gradle.kts
+++ b/build.gradle.kts
2024-04-23 19:23:27 +00:00
@@ -34,6 +34,7 @@ dependencies {
2024-04-06 19:53:39 +00:00
implementation("org.ow2.asm:asm-commons:9.7")
2023-10-04 01:06:23 +00:00
implementation("org.spongepowered:configurate-yaml:4.2.0-SNAPSHOT") // Paper - config files
2022-06-09 08:51:45 +00:00
implementation("commons-lang:commons-lang:2.6")
2023-11-28 22:18:21 +00:00
+ implementation("net.fabricmc:mapping-io:0.5.0") // Paper - needed to read mappings for stacktrace deobfuscation
2022-06-09 08:51:45 +00:00
runtimeOnly("com.lmax:disruptor:3.4.4") // Paper
2021-06-21 08:09:18 +00:00
2024-04-23 19:23:27 +00:00
runtimeOnly("org.apache.maven:maven-resolver-provider:3.9.6")
2023-07-02 05:00:46 +00:00
diff --git a/src/log4jPlugins/java/io/papermc/paper/logging/StacktraceDeobfuscatingRewritePolicy.java b/src/log4jPlugins/java/io/papermc/paper/logging/StacktraceDeobfuscatingRewritePolicy.java
2021-06-21 08:09:18 +00:00
new file mode 100644
2023-07-02 05:00:46 +00:00
index 0000000000000000000000000000000000000000..66b6011ee3684695b2ab9292961c80bf2a420ee9
2021-06-21 08:09:18 +00:00
--- /dev/null
2023-07-02 05:00:46 +00:00
+++ b/src/log4jPlugins/java/io/papermc/paper/logging/StacktraceDeobfuscatingRewritePolicy.java
@@ -0,0 +1,66 @@
2021-06-21 08:09:18 +00:00
+package io.papermc.paper.logging;
+
2023-07-02 05:00:46 +00:00
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
2021-06-22 04:12:07 +00:00
+import org.apache.logging.log4j.core.Core;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.appender.rewrite.RewritePolicy;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
2021-09-30 18:05:51 +00:00
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.checkerframework.checker.nullness.qual.NonNull;
2021-06-22 04:12:07 +00:00
+
+@Plugin(
+ name = "StacktraceDeobfuscatingRewritePolicy",
+ category = Core.CATEGORY_NAME,
+ elementType = "rewritePolicy",
+ printObject = true
+)
+public final class StacktraceDeobfuscatingRewritePolicy implements RewritePolicy {
2023-07-02 05:00:46 +00:00
+ private static final MethodHandle DEOBFUSCATE_THROWABLE;
+
+ static {
+ try {
+ final Class<?> cls = Class.forName("io.papermc.paper.util.StacktraceDeobfuscator");
+ final MethodHandles.Lookup lookup = MethodHandles.lookup();
+ final VarHandle instanceHandle = lookup.findStaticVarHandle(cls, "INSTANCE", cls);
+ final Object deobfuscator = instanceHandle.get();
+ DEOBFUSCATE_THROWABLE = lookup
+ .unreflect(cls.getDeclaredMethod("deobfuscateThrowable", Throwable.class))
+ .bindTo(deobfuscator);
+ } catch (final ReflectiveOperationException ex) {
+ throw new IllegalStateException(ex);
+ }
+ }
+
2021-09-30 18:05:51 +00:00
+ private StacktraceDeobfuscatingRewritePolicy() {
+ }
+
2021-06-22 04:12:07 +00:00
+ @Override
2021-09-30 18:05:51 +00:00
+ public @NonNull LogEvent rewrite(final @NonNull LogEvent rewrite) {
2021-06-22 04:12:07 +00:00
+ final Throwable thrown = rewrite.getThrown();
+ if (thrown != null) {
2023-07-02 05:00:46 +00:00
+ deobfuscateThrowable(thrown);
2021-09-30 18:05:51 +00:00
+ return new Log4jLogEvent.Builder(rewrite)
+ .setThrownProxy(null)
+ .build();
2021-06-22 04:12:07 +00:00
+ }
+ return rewrite;
+ }
+
2023-07-02 05:00:46 +00:00
+ private static void deobfuscateThrowable(final Throwable thrown) {
+ try {
+ DEOBFUSCATE_THROWABLE.invoke(thrown);
+ } catch (final Error e) {
+ throw e;
+ } catch (final Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+
2021-06-22 04:12:07 +00:00
+ @PluginFactory
2021-09-30 18:05:51 +00:00
+ public static @NonNull StacktraceDeobfuscatingRewritePolicy createPolicy() {
2021-06-22 04:12:07 +00:00
+ return new StacktraceDeobfuscatingRewritePolicy();
+ }
+}
2021-07-20 02:22:18 +00:00
diff --git a/src/main/java/io/papermc/paper/util/ObfHelper.java b/src/main/java/io/papermc/paper/util/ObfHelper.java
2021-06-22 04:12:07 +00:00
new file mode 100644
2023-11-28 22:18:21 +00:00
index 0000000000000000000000000000000000000000..e8ff684d8bd994c64ff34f20e1e0601b678244c1
2021-06-22 04:12:07 +00:00
--- /dev/null
2021-07-20 02:22:18 +00:00
+++ b/src/main/java/io/papermc/paper/util/ObfHelper.java
2023-11-28 22:18:21 +00:00
@@ -0,0 +1,147 @@
2021-06-22 04:12:07 +00:00
+package io.papermc.paper.util;
+
2021-06-21 08:09:18 +00:00
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
2021-11-05 00:23:06 +00:00
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.HashSet;
2021-06-21 08:09:18 +00:00
+import java.util.Map;
2023-11-28 22:18:21 +00:00
+import java.util.Objects;
2021-08-14 10:06:17 +00:00
+import java.util.Set;
2021-11-05 00:23:06 +00:00
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import net.fabricmc.mappingio.MappingReader;
+import net.fabricmc.mappingio.format.MappingFormat;
+import net.fabricmc.mappingio.tree.MappingTree;
+import net.fabricmc.mappingio.tree.MemoryMappingTree;
2021-07-20 02:22:18 +00:00
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.checkerframework.framework.qual.DefaultQualifier;
2021-06-21 08:09:18 +00:00
+
2021-07-20 02:22:18 +00:00
+@DefaultQualifier(NonNull.class)
+public enum ObfHelper {
2021-06-22 04:12:07 +00:00
+ INSTANCE;
+
2021-07-20 02:22:18 +00:00
+ public static final String MOJANG_PLUS_YARN_NAMESPACE = "mojang+yarn";
+ public static final String SPIGOT_NAMESPACE = "spigot";
2021-06-21 08:09:18 +00:00
+
2021-08-14 10:06:17 +00:00
+ private final @Nullable Map<String, ClassMapping> mappingsByObfName;
+ private final @Nullable Map<String, ClassMapping> mappingsByMojangName;
2021-06-21 08:09:18 +00:00
+
2021-07-20 02:22:18 +00:00
+ ObfHelper() {
2021-08-14 10:06:17 +00:00
+ final @Nullable Set<ClassMapping> maps = loadMappingsIfPresent();
+ if (maps != null) {
2021-11-05 00:23:06 +00:00
+ this.mappingsByObfName = maps.stream().collect(Collectors.toUnmodifiableMap(ClassMapping::obfName, map -> map));
+ this.mappingsByMojangName = maps.stream().collect(Collectors.toUnmodifiableMap(ClassMapping::mojangName, map -> map));
2021-08-14 10:06:17 +00:00
+ } else {
+ this.mappingsByObfName = null;
+ this.mappingsByMojangName = null;
+ }
+ }
+
+ public @Nullable Map<String, ClassMapping> mappingsByObfName() {
+ return this.mappingsByObfName;
+ }
+
+ public @Nullable Map<String, ClassMapping> mappingsByMojangName() {
+ return this.mappingsByMojangName;
2021-06-21 08:09:18 +00:00
+ }
+
2021-08-14 10:06:17 +00:00
+ /**
+ * Attempts to get the obf name for a given class by its Mojang name. Will
+ * return the input string if mappings are not present.
+ *
+ * @param fullyQualifiedMojangName fully qualified class name (dotted)
+ * @return mapped or original fully qualified (dotted) class name
+ */
+ public String reobfClassName(final String fullyQualifiedMojangName) {
+ if (this.mappingsByMojangName == null) {
+ return fullyQualifiedMojangName;
+ }
+
+ final ClassMapping map = this.mappingsByMojangName.get(fullyQualifiedMojangName);
+ if (map == null) {
+ return fullyQualifiedMojangName;
+ }
+
+ return map.obfName();
+ }
+
+ /**
+ * Attempts to get the Mojang name for a given class by its obf name. Will
+ * return the input string if mappings are not present.
+ *
+ * @param fullyQualifiedObfName fully qualified class name (dotted)
+ * @return mapped or original fully qualified (dotted) class name
+ */
+ public String deobfClassName(final String fullyQualifiedObfName) {
+ if (this.mappingsByObfName == null) {
+ return fullyQualifiedObfName;
+ }
+
+ final ClassMapping map = this.mappingsByObfName.get(fullyQualifiedObfName);
+ if (map == null) {
+ return fullyQualifiedObfName;
+ }
+
+ return map.mojangName();
2021-07-20 02:22:18 +00:00
+ }
+
2021-08-14 10:06:17 +00:00
+ private static @Nullable Set<ClassMapping> loadMappingsIfPresent() {
2021-09-09 16:57:16 +00:00
+ try (final @Nullable InputStream mappingsInputStream = ObfHelper.class.getClassLoader().getResourceAsStream("META-INF/mappings/reobf.tiny")) {
2021-06-21 08:09:18 +00:00
+ if (mappingsInputStream == null) {
+ return null;
+ }
2021-11-05 00:23:06 +00:00
+ final MemoryMappingTree tree = new MemoryMappingTree();
2023-11-28 22:18:21 +00:00
+ MappingReader.read(new InputStreamReader(mappingsInputStream, StandardCharsets.UTF_8), MappingFormat.TINY_2_FILE, tree);
2021-11-05 00:23:06 +00:00
+ final Set<ClassMapping> classes = new HashSet<>();
+
+ final StringPool pool = new StringPool();
+ for (final MappingTree.ClassMapping cls : tree.getClasses()) {
+ final Map<String, String> methods = new HashMap<>();
+
+ for (final MappingTree.MethodMapping methodMapping : cls.getMethods()) {
+ methods.put(
+ pool.string(methodKey(
2023-11-28 22:18:21 +00:00
+ Objects.requireNonNull(methodMapping.getName(SPIGOT_NAMESPACE)),
+ Objects.requireNonNull(methodMapping.getDesc(SPIGOT_NAMESPACE))
2021-11-05 00:23:06 +00:00
+ )),
2023-11-28 22:18:21 +00:00
+ pool.string(Objects.requireNonNull(methodMapping.getName(MOJANG_PLUS_YARN_NAMESPACE)))
2021-06-21 08:09:18 +00:00
+ );
+ }
+
+ final ClassMapping map = new ClassMapping(
2023-11-28 22:18:21 +00:00
+ Objects.requireNonNull(cls.getName(SPIGOT_NAMESPACE)).replace('/', '.'),
+ Objects.requireNonNull(cls.getName(MOJANG_PLUS_YARN_NAMESPACE)).replace('/', '.'),
2021-11-05 00:23:06 +00:00
+ Map.copyOf(methods)
2021-06-21 08:09:18 +00:00
+ );
2021-11-05 00:23:06 +00:00
+ classes.add(map);
2021-06-21 08:09:18 +00:00
+ }
+
2021-11-05 00:23:06 +00:00
+ return Set.copyOf(classes);
2021-06-21 08:09:18 +00:00
+ } catch (final IOException ex) {
+ System.err.println("Failed to load mappings for stacktrace deobfuscation.");
+ ex.printStackTrace();
+ return null;
+ }
+ }
+
2021-11-05 00:23:06 +00:00
+ public static String methodKey(final String obfName, final String obfDescriptor) {
+ return obfName + obfDescriptor;
+ }
2021-07-20 02:22:18 +00:00
+
2021-11-05 00:23:06 +00:00
+ private static final class StringPool {
+ private final Map<String, String> pool = new HashMap<>();
+
+ public String string(final String string) {
+ return this.pool.computeIfAbsent(string, Function.identity());
+ }
+ }
+
+ public record ClassMapping(
2021-07-20 02:22:18 +00:00
+ String obfName,
+ String mojangName,
2021-11-05 00:23:06 +00:00
+ Map<String, String> methodsByObf
2021-07-20 02:22:18 +00:00
+ ) {}
+}
diff --git a/src/main/java/io/papermc/paper/util/StacktraceDeobfuscator.java b/src/main/java/io/papermc/paper/util/StacktraceDeobfuscator.java
new file mode 100644
2022-06-09 08:51:45 +00:00
index 0000000000000000000000000000000000000000..eb910d4abf91488fa7cf1f5d47e0ee916c47f512
2021-07-20 02:22:18 +00:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/util/StacktraceDeobfuscator.java
2021-11-26 06:33:08 +00:00
@@ -0,0 +1,163 @@
2021-07-20 02:22:18 +00:00
+package io.papermc.paper.util;
+
2022-06-09 08:51:45 +00:00
+import io.papermc.paper.configuration.GlobalConfiguration;
2021-07-20 02:22:18 +00:00
+import it.unimi.dsi.fastutil.ints.IntArrayList;
+import it.unimi.dsi.fastutil.ints.IntList;
+import java.io.IOException;
2021-11-26 06:33:08 +00:00
+import java.io.InputStream;
2021-07-20 02:22:18 +00:00
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.checkerframework.framework.qual.DefaultQualifier;
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.Label;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+
+@DefaultQualifier(NonNull.class)
+public enum StacktraceDeobfuscator {
+ INSTANCE;
+
2021-11-05 00:23:06 +00:00
+ private final Map<Class<?>, Map<String, IntList>> lineMapCache = Collections.synchronizedMap(new LinkedHashMap<>(128, 0.75f, true) {
2021-07-20 02:22:18 +00:00
+ @Override
2021-11-05 00:23:06 +00:00
+ protected boolean removeEldestEntry(final Map.Entry<Class<?>, Map<String, IntList>> eldest) {
2021-07-20 02:22:18 +00:00
+ return this.size() > 127;
+ }
+ });
+
2021-06-22 04:12:07 +00:00
+ public void deobfuscateThrowable(final Throwable throwable) {
2022-06-09 08:51:45 +00:00
+ if (GlobalConfiguration.get() != null && !GlobalConfiguration.get().logging.deobfuscateStacktraces) { // handle null as true
2021-06-22 04:12:07 +00:00
+ return;
2021-06-21 08:09:18 +00:00
+ }
+
+ throwable.setStackTrace(this.deobfuscateStacktrace(throwable.getStackTrace()));
+ final Throwable cause = throwable.getCause();
+ if (cause != null) {
+ this.deobfuscateThrowable(cause);
+ }
+ for (final Throwable suppressed : throwable.getSuppressed()) {
+ this.deobfuscateThrowable(suppressed);
+ }
+ }
+
+ public StackTraceElement[] deobfuscateStacktrace(final StackTraceElement[] traceElements) {
2022-06-09 08:51:45 +00:00
+ if (GlobalConfiguration.get() != null && !GlobalConfiguration.get().logging.deobfuscateStacktraces) { // handle null as true
2021-06-22 04:12:07 +00:00
+ return traceElements;
+ }
+
2021-08-14 10:06:17 +00:00
+ final @Nullable Map<String, ObfHelper.ClassMapping> mappings = ObfHelper.INSTANCE.mappingsByObfName();
2021-07-20 02:22:18 +00:00
+ if (mappings == null || traceElements.length == 0) {
2021-06-21 08:09:18 +00:00
+ return traceElements;
+ }
+ final StackTraceElement[] result = new StackTraceElement[traceElements.length];
+ for (int i = 0; i < traceElements.length; i++) {
+ final StackTraceElement element = traceElements[i];
+
+ final String className = element.getClassName();
+ final String methodName = element.getMethodName();
+
2021-07-20 02:22:18 +00:00
+ final ObfHelper.ClassMapping classMapping = mappings.get(className);
2021-06-21 08:09:18 +00:00
+ if (classMapping == null) {
+ result[i] = element;
+ continue;
+ }
+
2021-07-20 02:22:18 +00:00
+ final Class<?> clazz;
2021-06-21 08:09:18 +00:00
+ try {
2021-07-20 02:22:18 +00:00
+ clazz = Class.forName(className);
+ } catch (final ClassNotFoundException ex) {
2021-06-21 08:09:18 +00:00
+ throw new RuntimeException(ex);
+ }
2021-11-05 00:23:06 +00:00
+ final @Nullable String methodKey = this.determineMethodForLine(clazz, element.getLineNumber());
+ final @Nullable String mappedMethodName = methodKey == null ? null : classMapping.methodsByObf().get(methodKey);
2021-06-21 08:09:18 +00:00
+
+ result[i] = new StackTraceElement(
+ element.getClassLoaderName(),
+ element.getModuleName(),
+ element.getModuleVersion(),
+ classMapping.mojangName(),
2021-11-05 00:23:06 +00:00
+ mappedMethodName != null ? mappedMethodName : methodName,
2021-07-20 02:22:18 +00:00
+ sourceFileName(classMapping.mojangName()),
2021-06-21 08:09:18 +00:00
+ element.getLineNumber()
+ );
+ }
+ return result;
+ }
+
2021-11-05 00:23:06 +00:00
+ private @Nullable String determineMethodForLine(final Class<?> clazz, final int lineNumber) {
+ final Map<String, IntList> lineMap = this.lineMapCache.computeIfAbsent(clazz, StacktraceDeobfuscator::buildLineMap);
2021-07-20 02:22:18 +00:00
+ for (final var entry : lineMap.entrySet()) {
2021-11-05 00:23:06 +00:00
+ final String methodKey = entry.getKey();
2021-07-20 02:22:18 +00:00
+ final IntList lines = entry.getValue();
+ for (int i = 0, linesSize = lines.size(); i < linesSize; i++) {
+ final int num = lines.getInt(i);
+ if (num == lineNumber) {
2021-11-05 00:23:06 +00:00
+ return methodKey;
2021-07-20 02:22:18 +00:00
+ }
+ }
+ }
+ return null;
+ }
+
+ private static String sourceFileName(final String fullClassName) {
+ final int dot = fullClassName.lastIndexOf('.');
+ final String className = dot == -1
+ ? fullClassName
+ : fullClassName.substring(dot + 1);
+ final String rootClassName = className.split("\\$")[0];
+ return rootClassName + ".java";
+ }
+
2021-11-05 00:23:06 +00:00
+ private static Map<String, IntList> buildLineMap(final Class<?> key) {
+ final Map<String, IntList> lineMap = new HashMap<>();
2021-06-21 08:09:18 +00:00
+ final class LineCollectingMethodVisitor extends MethodVisitor {
+ private final IntList lines = new IntArrayList();
+ private final String name;
+ private final String descriptor;
+
+ LineCollectingMethodVisitor(String name, String descriptor) {
+ super(Opcodes.ASM9);
+ this.name = name;
+ this.descriptor = descriptor;
+ }
+
+ @Override
+ public void visitLineNumber(int line, Label start) {
+ super.visitLineNumber(line, start);
+ this.lines.add(line);
+ }
+
+ @Override
+ public void visitEnd() {
+ super.visitEnd();
2021-11-05 00:23:06 +00:00
+ lineMap.put(ObfHelper.methodKey(this.name, this.descriptor), this.lines);
2021-06-21 08:09:18 +00:00
+ }
+ }
+ final ClassVisitor classVisitor = new ClassVisitor(Opcodes.ASM9) {
+ @Override
+ public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
+ return new LineCollectingMethodVisitor(name, descriptor);
+ }
+ };
+ try {
2021-11-26 06:33:08 +00:00
+ final @Nullable InputStream inputStream = StacktraceDeobfuscator.class.getClassLoader()
+ .getResourceAsStream(key.getName().replace('.', '/') + ".class");
+ if (inputStream == null) {
+ throw new IllegalStateException("Could not find class file: " + key.getName());
+ }
+ final byte[] classData;
+ try (inputStream) {
+ classData = inputStream.readAllBytes();
+ }
+ final ClassReader reader = new ClassReader(classData);
2021-06-21 08:09:18 +00:00
+ reader.accept(classVisitor, 0);
+ } catch (final IOException ex) {
+ throw new RuntimeException(ex);
+ }
+ return lineMap;
+ }
+}
2021-06-22 04:12:07 +00:00
diff --git a/src/main/java/net/minecraft/CrashReport.java b/src/main/java/net/minecraft/CrashReport.java
2024-04-23 19:23:27 +00:00
index a23407fa1b906743890cff74f5051ad55d59c85e..06c514b2d0674cd7df6692981f020437ea0f2f91 100644
2021-06-22 04:12:07 +00:00
--- a/src/main/java/net/minecraft/CrashReport.java
+++ b/src/main/java/net/minecraft/CrashReport.java
2023-12-05 22:55:31 +00:00
@@ -34,6 +34,7 @@ public class CrashReport {
2021-06-22 04:12:07 +00:00
private final SystemReport systemReport = new SystemReport();
public CrashReport(String message, Throwable cause) {
+ io.papermc.paper.util.StacktraceDeobfuscator.INSTANCE.deobfuscateThrowable(cause); // Paper
this.title = message;
this.exception = cause;
this.systemReport.setDetail("CraftBukkit Information", new org.bukkit.craftbukkit.CraftCrashReport()); // CraftBukkit
2021-07-04 10:20:11 +00:00
diff --git a/src/main/java/net/minecraft/CrashReportCategory.java b/src/main/java/net/minecraft/CrashReportCategory.java
2024-04-23 17:02:08 +00:00
index f367ba058018074bfe6e4fe88bcc875ea9794d9e..2176171954609fd88f97f93408e14e018c1d6eaa 100644
2021-07-04 10:20:11 +00:00
--- a/src/main/java/net/minecraft/CrashReportCategory.java
+++ b/src/main/java/net/minecraft/CrashReportCategory.java
2024-04-12 19:14:06 +00:00
@@ -110,6 +110,7 @@ public class CrashReportCategory {
2021-07-04 10:20:11 +00:00
} else {
this.stackTrace = new StackTraceElement[stackTraceElements.length - 3 - ignoredCallCount];
System.arraycopy(stackTraceElements, 3 + ignoredCallCount, this.stackTrace, 0, this.stackTrace.length);
+ this.stackTrace = io.papermc.paper.util.StacktraceDeobfuscator.INSTANCE.deobfuscateStacktrace(this.stackTrace); // Paper
return this.stackTrace.length;
}
}
2021-12-23 10:32:26 +00:00
diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java
2024-04-23 19:23:27 +00:00
index 256a983c7345902600d52d7b7e3056162275f4c7..0ccfdceea8e211c595be2dad2392876109b4eeef 100644
2021-12-23 10:32:26 +00:00
--- a/src/main/java/net/minecraft/network/Connection.java
+++ b/src/main/java/net/minecraft/network/Connection.java
2024-04-23 19:23:27 +00:00
@@ -82,13 +82,13 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
marker.add(Connection.PACKET_MARKER);
});
2023-09-22 04:05:18 +00:00
public static final Supplier<NioEventLoopGroup> NETWORK_WORKER_GROUP = Suppliers.memoize(() -> {
2021-12-23 10:32:26 +00:00
- return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Client IO #%d").setDaemon(true).build());
+ return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Client IO #%d").setDaemon(true).setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(LOGGER)).build()); // Paper
});
2023-09-22 04:05:18 +00:00
public static final Supplier<EpollEventLoopGroup> NETWORK_EPOLL_WORKER_GROUP = Suppliers.memoize(() -> {
2021-12-23 10:32:26 +00:00
- return new EpollEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Epoll Client IO #%d").setDaemon(true).build());
+ return new EpollEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Epoll Client IO #%d").setDaemon(true).setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(LOGGER)).build()); // Paper
});
2023-09-22 04:05:18 +00:00
public static final Supplier<DefaultEventLoopGroup> LOCAL_WORKER_GROUP = Suppliers.memoize(() -> {
2021-12-23 10:32:26 +00:00
- return new DefaultEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Local Client IO #%d").setDaemon(true).build());
+ return new DefaultEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Local Client IO #%d").setDaemon(true).setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(LOGGER)).build()); // Paper
});
2024-04-23 19:23:27 +00:00
private static final ProtocolInfo<ServerHandshakePacketListener> INITIAL_PROTOCOL = HandshakeProtocols.SERVERBOUND;
2021-12-23 10:32:26 +00:00
private final PacketFlow receiving;
2024-04-23 19:23:27 +00:00
@@ -189,7 +189,7 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
2022-10-19 02:21:07 +00:00
}
}
- if (net.minecraft.server.MinecraftServer.getServer().isDebugging()) throwable.printStackTrace(); // Spigot
+ if (net.minecraft.server.MinecraftServer.getServer().isDebugging()) io.papermc.paper.util.TraceUtil.printStackTrace(throwable); // Spigot // Paper
}
protected void channelRead0(ChannelHandlerContext channelhandlercontext, Packet<?> packet) {
2021-06-22 04:12:07 +00:00
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
2024-04-23 19:23:27 +00:00
index 9249122da7282929f87613f41984b8085d7b53ec..21b8f1913ff54d2b1553826269355da8bdb7f702 100644
2021-06-22 04:12:07 +00:00
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
2024-04-23 19:23:27 +00:00
@@ -206,6 +206,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
2024-01-13 20:31:02 +00:00
org.spigotmc.SpigotConfig.init((java.io.File) this.options.valueOf("spigot-settings"));
2022-06-09 08:51:45 +00:00
org.spigotmc.SpigotConfig.registerCommands();
// Spigot end
+ io.papermc.paper.util.ObfHelper.INSTANCE.getClass(); // Paper - load mappings for stacktrace deobf and etc.
2024-01-13 20:31:02 +00:00
// Paper start - initialize global and world-defaults configuration
this.paperConfigurations.initializeGlobalConfiguration(this.registryAccess());
this.paperConfigurations.initializeWorldDefaultsConfiguration(this.registryAccess());
2021-12-23 10:32:26 +00:00
diff --git a/src/main/java/net/minecraft/server/network/ServerConnectionListener.java b/src/main/java/net/minecraft/server/network/ServerConnectionListener.java
2024-04-23 19:23:27 +00:00
index 987360a266a5a870f06929b00c9f451901188fd6..2cf3e79ec5e8706b71d27ebad4668773f0b91195 100644
2021-12-23 10:32:26 +00:00
--- a/src/main/java/net/minecraft/server/network/ServerConnectionListener.java
+++ b/src/main/java/net/minecraft/server/network/ServerConnectionListener.java
2023-09-22 04:05:18 +00:00
@@ -52,10 +52,10 @@ public class ServerConnectionListener {
2021-12-23 10:32:26 +00:00
2022-03-01 05:43:03 +00:00
private static final Logger LOGGER = LogUtils.getLogger();
2023-09-22 04:05:18 +00:00
public static final Supplier<NioEventLoopGroup> SERVER_EVENT_GROUP = Suppliers.memoize(() -> {
2021-12-23 10:32:26 +00:00
- return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Server IO #%d").setDaemon(true).build());
+ return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Server IO #%d").setDaemon(true).setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(LOGGER)).build()); // Paper
});
2023-09-22 04:05:18 +00:00
public static final Supplier<EpollEventLoopGroup> SERVER_EPOLL_EVENT_GROUP = Suppliers.memoize(() -> {
2021-12-23 10:32:26 +00:00
- return new EpollEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Epoll Server IO #%d").setDaemon(true).build());
+ return new EpollEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Epoll Server IO #%d").setDaemon(true).setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(LOGGER)).build()); // Paper
});
final MinecraftServer server;
public volatile boolean running;
2022-10-19 02:21:07 +00:00
diff --git a/src/main/java/net/minecraft/server/players/OldUsersConverter.java b/src/main/java/net/minecraft/server/players/OldUsersConverter.java
2024-04-23 19:23:27 +00:00
index 8d06e8d286da2573e40794adab695ff77e5afd86..68551947f5b7d3471f15bd74ccd86519ab34c1c1 100644
2022-10-19 02:21:07 +00:00
--- a/src/main/java/net/minecraft/server/players/OldUsersConverter.java
+++ b/src/main/java/net/minecraft/server/players/OldUsersConverter.java
2024-04-23 19:23:27 +00:00
@@ -356,7 +356,7 @@ public class OldUsersConverter {
2022-10-19 02:21:07 +00:00
try {
2023-12-05 22:55:31 +00:00
root = NbtIo.readCompressed(new java.io.FileInputStream(file5), NbtAccounter.unlimitedHeap());
2022-10-19 02:21:07 +00:00
} catch (Exception exception) {
- exception.printStackTrace();
+ io.papermc.paper.util.TraceUtil.printStackTrace(exception); // Paper
}
2024-04-23 19:23:27 +00:00
if (root != null) {
@@ -369,7 +369,7 @@ public class OldUsersConverter {
2022-10-19 02:21:07 +00:00
try {
NbtIo.writeCompressed(root, new java.io.FileOutputStream(file2));
} catch (Exception exception) {
- exception.printStackTrace();
+ io.papermc.paper.util.TraceUtil.printStackTrace(exception); // Paper
}
}
2024-04-23 19:23:27 +00:00
// CraftBukkit end
2021-06-22 04:12:07 +00:00
diff --git a/src/main/java/org/spigotmc/WatchdogThread.java b/src/main/java/org/spigotmc/WatchdogThread.java
2024-04-23 19:23:27 +00:00
index c4bf7053d83d207caca0e13e19f5c1afa7062de3..f697d45e0ac4e9cdc8a46121510a04c0f294d91f 100644
2021-06-22 04:12:07 +00:00
--- a/src/main/java/org/spigotmc/WatchdogThread.java
+++ b/src/main/java/org/spigotmc/WatchdogThread.java
2024-04-23 19:23:27 +00:00
@@ -130,7 +130,7 @@ public class WatchdogThread extends Thread
2021-06-22 04:12:07 +00:00
}
2024-01-24 13:05:59 +00:00
log.log( Level.SEVERE, "\tStack:" );
//
2021-06-22 04:12:07 +00:00
- for ( StackTraceElement stack : thread.getStackTrace() )
+ for ( StackTraceElement stack : io.papermc.paper.util.StacktraceDeobfuscator.INSTANCE.deobfuscateStacktrace(thread.getStackTrace()) ) // Paper
{
log.log( Level.SEVERE, "\t\t" + stack );
}
2021-06-21 08:09:18 +00:00
diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml
2024-04-23 19:23:27 +00:00
index 18e961a37b2830da6e5dab7aa35116b2f5215898..128fa1376f22d3429a23d79a2772abf2e7fec2bc 100644
2021-06-21 08:09:18 +00:00
--- a/src/main/resources/log4j2.xml
+++ b/src/main/resources/log4j2.xml
2021-08-12 17:55:20 +00:00
@@ -30,10 +30,14 @@
2021-06-21 08:09:18 +00:00
<DefaultRolloverStrategy max="1000"/>
</RollingRandomAccessFile>
2021-08-12 17:55:20 +00:00
<Async name="Async">
+ <AppenderRef ref="rewrite"/>
+ </Async>
2021-06-21 08:09:18 +00:00
+ <Rewrite name="rewrite">
+ <StacktraceDeobfuscatingRewritePolicy />
2021-08-12 17:55:20 +00:00
<AppenderRef ref="File"/>
<AppenderRef ref="TerminalConsole" level="info"/>
<AppenderRef ref="ServerGuiConsole" level="info"/>
- </Async>
2021-06-21 08:09:18 +00:00
+ </Rewrite>
</Appenders>
<Loggers>
<Root level="info">