Yatopia/patches/server/0068-Fix-Log4j-Warning.patch
Simon Gardling e01705826c
Upstream (#484)
* Updated Upstream and Sidestream(s) (Paper/Purpur/Empirecraft)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Paper Changes:
2a67a9e51 Fix missing CraftMetaBook#toBuilder override
48aa06106 Add more Wandering Trader API (#5020)
8cec462a5 [CI-SKIP] Remove Astei from the MIT list (#5577)
21fbc3196 [CI-SKIP] Add Other textarea to issue templates (#5562)
453e983e4 fix isProxyOnlineMode coverage, don't lookup UUIDs in offline mode (Fixes #2011)
81cc4f928 Send empty commands if tab completion is disabled (Closes #5519)
9ed3e470d Keep moveToWorld with old method signature
99a66a583 [Auto] Updated Upstream (CraftBukkit)
976c6d425 [CI-SKIP] [Auto] Rebuild Patches
51deec726 Drop unneeded portal patch (#5566)
07a18c457 [Auto] Updated Upstream (CraftBukkit)
6733d7875 [Auto] Updated Upstream (Bukkit)
9958447cb [Auto] Updated Upstream (Bukkit)
840e72091 [CI-SKIP] [Auto] Rebuild Patches
a33232d4a Add beacon activation and deactivation events (#5121)

Purpur Changes:
ebc0765 Updated Upstream (Paper)
5bc5dfd Fix #318 - Stonecutter does not damage when sneaking
8366582 Resolve #286 - Add config and API for item immunity to lightning
a86555b Updated Upstream (Paper)
8b2607c Config for only sending advancements to affected players (#312)
7ee3393 Add config for the piston push limit (#311)
a30e5ac Add config for void damage dealt
786382b Updated Upstream (Paper)
60d8411 [ci-skip] fix patch name
b64f536 Config for changing the blocks that turn into paths (#303)
1d3f710 Updated Upstream (Paper)
3af86ad Oopsie
4b0342a Gamemode extra permissions
17c8573 [CI-SKIP] Don't pass ping to demo command output
c3481c0 Initialize the credits command output in config
a176fe6 Add credits command

Empirecraft Changes:
b2879a24 Updated Paper

* Updated Upstream and Sidestream(s) (Paper/Tuinity/Airplane/Purpur/Empirecraft)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Paper Changes:
b3cc88799 Add the ability to clear entities from block storage (#5598)
f50171f3b Add missing rarity method on ItemStack (#5594)
aeb6e7dd2 Updated Upstream (Bukkit/CraftBukkit/Spigot) (#5601)
b0a4f353b fix cancelling block falling causing client desync (fixes #5386) (#5419)
8ed45920c Don't annotate type parameters using JetBrains annotations (#5600)
d7625d926 Add new methods from PlayerMoveEvent to EntityMoveEvent (#5591)
29785297b Allow for Component suggestion tooltips in AsyncTabCompleteEvent (#5504)
0aea6c2ff Use JsonSerializationContext#serialize instead of recursion for AdventureComponents - fixes #5580 and #5371
8fcef3c1f Return after sending empty commands (#5586)

Tuinity Changes:
3350246 Updated Upstream (Paper)
f773caf Fix rare ticket level recursion crash
0fa8a0e Starlight Handle concurrent chunk generation and lighting better

Airplane Changes:
fad74c2 Fix JB annotations for gradle (credit jpenilla)
d02f034 Updated Upstream (Tuinity)

Purpur Changes:
adfe5d3 Updated Upstream (Paper)
7a728f8 Fix #325 - Fix SPIGOT-6278
f5c3dae Updated Upstream (Paper)
a80e5b6 Dont create item meta when checking if meta properties exist
90339c5 Add missing netherite from Material#isArmor
bedac18 Updated Upstream (Paper, Tuinity, & Airplane)
3b1531a [ci-skip] Add wrapper validation step to actions
73ab4e6 Update the "changing the blocks that turn into paths" defaults to reflect the vanilla defaults. (#322)
a24b31b Updated Upstream (Paper)

Empirecraft Changes:
87ceb204 Updated Paper
a3497a7e Fix some patches
2ed9e7fa Updated Paper
d5a47a3d Updated Paper

* Updated Upstream and Sidestream(s) (Tuinity)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Tuinity Changes:
1382473 Null check chunk in block changes for Starlight
2021-05-10 23:16:50 -04:00

263 lines
11 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: snoopdoooggyttv <snoopdoooggyttv@users.noreply.github.com>
Date: Wed, 5 May 2021 20:32:22 +0200
Subject: [PATCH] Fix Log4j Warning
diff --git a/src/main/java/org/apache/logging/log4j/util/StackLocator.java b/src/main/java/org/apache/logging/log4j/util/StackLocator.java
new file mode 100644
index 0000000000000000000000000000000000000000..44161840e64946b4b6ce0483495304809d15ade8
--- /dev/null
+++ b/src/main/java/org/apache/logging/log4j/util/StackLocator.java
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.util;
+
+import java.lang.reflect.Method;
+import java.util.Stack;
+
+/**
+ * <em>Consider this class private.</em> Provides various methods to determine the caller class. <h3>Background</h3>
+ * <p>
+ * This method, available only in the Oracle/Sun/OpenJDK implementations of the Java Virtual Machine, is a much more
+ * efficient mechanism for determining the {@link Class} of the caller of a particular method. When it is not available,
+ * a {@link SecurityManager} is the second-best option. When this is also not possible, the {@code StackTraceElement[]}
+ * returned by {@link Throwable#getStackTrace()} must be used, and its {@code String} class name converted to a
+ * {@code Class} using the slow {@link Class#forName} (which can add an extra microsecond or more for each invocation
+ * depending on the runtime ClassLoader hierarchy).
+ * </p>
+ * <p>
+ * During Java 8 development, the {@code sun.reflect.Reflection.getCallerClass(int)} was removed from OpenJDK, and this
+ * change was back-ported to Java 7 in version 1.7.0_25 which changed the behavior of the call and caused it to be off
+ * by one stack frame. This turned out to be beneficial for the survival of this API as the change broke hundreds of
+ * libraries and frameworks relying on the API which brought much more attention to the intended API removal.
+ * </p>
+ * <p>
+ * After much community backlash, the JDK team agreed to restore {@code getCallerClass(int)} and keep its existing
+ * behavior for the rest of Java 7. However, the method is deprecated in Java 8, and current Java 9 development has not
+ * addressed this API. Therefore, the functionality of this class cannot be relied upon for all future versions of Java.
+ * It does, however, work just fine in Sun JDK 1.6, OpenJDK 1.6, Oracle/OpenJDK 1.7, and Oracle/OpenJDK 1.8. Other Java
+ * environments may fall back to using {@link Throwable#getStackTrace()} which is significantly slower due to
+ * examination of every virtual frame of execution.
+ * </p>
+ */
+public final class StackLocator {
+
+ // Checkstyle Suppress: the lower-case 'u' ticks off CheckStyle...
+ // CHECKSTYLE:OFF
+ static final int JDK_7u25_OFFSET;
+ // CHECKSTYLE:OFF
+
+ private static final Method GET_CALLER_CLASS;
+
+ private static final StackLocator INSTANCE;
+
+ static {
+ Method getCallerClass;
+ int java7u25CompensationOffset = 0;
+ try {
+ final Class<?> sunReflectionClass = LoaderUtil.loadClass("sun.reflect.Reflection");
+ getCallerClass = sunReflectionClass.getDeclaredMethod("getCallerClass", int.class);
+ Object o = getCallerClass.invoke(null, 0);
+ getCallerClass.invoke(null, 0);
+ if (o == null || o != sunReflectionClass) {
+ getCallerClass = null;
+ java7u25CompensationOffset = -1;
+ } else {
+ o = getCallerClass.invoke(null, 1);
+ if (o == sunReflectionClass) {
+ System.out.println("WARNING: Java 1.7.0_25 is in use which has a broken implementation of Reflection.getCallerClass(). " +
+ " Please consider upgrading to Java 1.7.0_40 or later.");
+ java7u25CompensationOffset = 1;
+ }
+ }
+ } catch (final Exception | LinkageError e) {
+ //System.out.println("WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance."); // Yatopia - Fix Error Message
+ getCallerClass = null;
+ java7u25CompensationOffset = -1;
+ }
+
+ GET_CALLER_CLASS = getCallerClass;
+ JDK_7u25_OFFSET = java7u25CompensationOffset;
+
+ INSTANCE = new StackLocator();
+ }
+
+ public static StackLocator getInstance() {
+ return INSTANCE;
+ }
+
+ private StackLocator() {
+ }
+
+ // TODO: return Object.class instead of null (though it will have a null ClassLoader)
+ // (MS) I believe this would work without any modifications elsewhere, but I could be wrong
+
+ // migrated from ReflectiveCallerClassUtility
+ @PerformanceSensitive
+ public Class<?> getCallerClass(final int depth) {
+ if (depth < 0) {
+ throw new IndexOutOfBoundsException(Integer.toString(depth));
+ }
+ if (GET_CALLER_CLASS == null) {
+ return null;
+ }
+ // note that we need to add 1 to the depth value to compensate for this method, but not for the Method.invoke
+ // since Reflection.getCallerClass ignores the call to Method.invoke()
+ try {
+ return (Class<?>) GET_CALLER_CLASS.invoke(null, depth + 1 + JDK_7u25_OFFSET);
+ } catch (final Exception e) {
+ // theoretically this could happen if the caller class were native code
+ // TODO: return Object.class
+ return null;
+ }
+ }
+
+ // migrated from Log4jLoggerFactory
+ @PerformanceSensitive
+ public Class<?> getCallerClass(final String fqcn, final String pkg) {
+ return getCallerClass(fqcn, pkg, 0);
+ }
+
+ @PerformanceSensitive
+ public Class<?> getCallerClass(final String fqcn, final String pkg, final int skipDepth) {
+ if (skipDepth < 0) {
+ throw new IllegalArgumentException("skipDepth cannot be negative");
+ }
+ boolean next = false;
+ Class<?> clazz;
+ for (int i = 2; null != (clazz = getCallerClass(i)); i++) {
+ if (fqcn.equals(clazz.getName())) {
+ next = true;
+ continue;
+ }
+ if (next && clazz.getName().startsWith(pkg)) {
+ return skipDepth == 0
+ ? clazz
+ : getCallerClass(i + skipDepth);
+ }
+ }
+ // TODO: return Object.class
+ return null;
+ }
+
+ // added for use in LoggerAdapter implementations mainly
+ @PerformanceSensitive
+ public Class<?> getCallerClass(final Class<?> anchor) {
+ boolean next = false;
+ Class<?> clazz;
+ for (int i = 2; null != (clazz = getCallerClass(i)); i++) {
+ if (anchor.equals(clazz)) {
+ next = true;
+ continue;
+ }
+ if (next) {
+ return clazz;
+ }
+ }
+ return Object.class;
+ }
+
+ // migrated from ThrowableProxy
+ @PerformanceSensitive
+ public Stack<Class<?>> getCurrentStackTrace() {
+ // benchmarks show that using the SecurityManager is much faster than looping through getCallerClass(int)
+ if (PrivateSecurityManagerStackTraceUtil.isEnabled()) {
+ return PrivateSecurityManagerStackTraceUtil.getCurrentStackTrace();
+ }
+ // slower version using getCallerClass where we cannot use a SecurityManager
+ final Stack<Class<?>> classes = new Stack<>();
+ Class<?> clazz;
+ for (int i = 1; null != (clazz = getCallerClass(i)); i++) {
+ classes.push(clazz);
+ }
+ return classes;
+ }
+
+ public StackTraceElement calcLocation(final String fqcnOfLogger) {
+ if (fqcnOfLogger == null) {
+ return null;
+ }
+ // LOG4J2-1029 new Throwable().getStackTrace is faster than Thread.currentThread().getStackTrace().
+ final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
+ boolean found = false;
+ for (int i = 0; i < stackTrace.length; i++) {
+ final String className = stackTrace[i].getClassName();
+ if (fqcnOfLogger.equals(className)) {
+
+ found = true;
+ continue;
+ }
+ if (found && !fqcnOfLogger.equals(className)) {
+ return stackTrace[i];
+ }
+ }
+ return null;
+ }
+
+ public StackTraceElement getStackTraceElement(final int depth) {
+ // (MS) I tested the difference between using Throwable.getStackTrace() and Thread.getStackTrace(), and
+ // the version using Throwable was surprisingly faster! at least on Java 1.8. See ReflectionBenchmark.
+ final StackTraceElement[] elements = new Throwable().getStackTrace();
+ int i = 0;
+ for (final StackTraceElement element : elements) {
+ if (isValid(element)) {
+ if (i == depth) {
+ return element;
+ }
+ ++i;
+ }
+ }
+ throw new IndexOutOfBoundsException(Integer.toString(depth));
+ }
+
+ private boolean isValid(final StackTraceElement element) {
+ // ignore native methods (oftentimes are repeated frames)
+ if (element.isNativeMethod()) {
+ return false;
+ }
+ final String cn = element.getClassName();
+ // ignore OpenJDK internal classes involved with reflective invocation
+ if (cn.startsWith("sun.reflect.")) {
+ return false;
+ }
+ final String mn = element.getMethodName();
+ // ignore use of reflection including:
+ // Method.invoke
+ // InvocationHandler.invoke
+ // Constructor.newInstance
+ if (cn.startsWith("java.lang.reflect.") && (mn.equals("invoke") || mn.equals("newInstance"))) {
+ return false;
+ }
+ // ignore use of Java 1.9+ reflection classes
+ if (cn.startsWith("jdk.internal.reflect.")) {
+ return false;
+ }
+ // ignore Class.newInstance
+ if (cn.equals("java.lang.Class") && mn.equals("newInstance")) {
+ return false;
+ }
+ // ignore use of Java 1.7+ MethodHandle.invokeFoo() methods
+ if (cn.equals("java.lang.invoke.MethodHandle") && mn.startsWith("invoke")) {
+ return false;
+ }
+ // any others?
+ return true;
+ }
+}