Redefine Cyclic Dependencies (#8873)

This commit is contained in:
Owen 2023-02-20 20:09:38 -05:00 committed by GitHub
parent 0e4f2cc527
commit 8427c88987
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 566 additions and 317 deletions

View file

@ -1942,7 +1942,7 @@ index 669a70faa95d0d6525a731d73499ed6fb0b48320..6175b04327b12e74140a0885f7326546
/**
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
index 047c0304fd617cec990f80815b43916c6ef5a94c..d0ad072c832b8fc8a1cfdcafdd42c724531a2e29 100644
index 047c0304fd617cec990f80815b43916c6ef5a94c..fa39c93d76ebb9eecce1f4b5203cb361e4778b4f 100644
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
@@ -49,6 +49,7 @@ import org.yaml.snakeyaml.error.YAMLException;
@ -1966,7 +1966,7 @@ index 047c0304fd617cec990f80815b43916c6ef5a94c..d0ad072c832b8fc8a1cfdcafdd42c724
final PluginClassLoader loader;
try {
- loader = new PluginClassLoader(this, getClass().getClassLoader(), description, dataFolder, file, (libraryLoader != null) ? libraryLoader.createLoader(description) : null);
+ loader = new PluginClassLoader(getClass().getClassLoader(), description, dataFolder, file, (libraryLoader != null) ? libraryLoader.createLoader(description) : null, null); // Paper
+ loader = new PluginClassLoader(getClass().getClassLoader(), description, dataFolder, file, (libraryLoader != null) ? libraryLoader.createLoader(description) : null); // Paper
} catch (InvalidPluginException ex) {
throw ex;
} catch (Throwable ex) {
@ -1987,7 +1987,7 @@ index 6d634b0ea813ccb19f1562a7d0e5a59cea4eab21..f9e67e20133d349e43d126dbb48b34d4
private final Logger logger;
diff --git a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61f96ab4b3 100644
index 2f74ec96ece706de23156ebabfe493211bc05391..f92071617712a0f410475fae291fb85f668e8e8a 100644
--- a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
+++ b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
@@ -29,7 +29,8 @@ import org.jetbrains.annotations.Nullable;
@ -2000,7 +2000,7 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61
private final JavaPluginLoader loader;
private final Map<String, Class<?>> classes = new ConcurrentHashMap<String, Class<?>>();
private final PluginDescriptionFile description;
@@ -39,20 +40,23 @@ final class PluginClassLoader extends URLClassLoader {
@@ -39,20 +40,22 @@ final class PluginClassLoader extends URLClassLoader {
private final Manifest manifest;
private final URL url;
private final ClassLoader libraryLoader;
@ -2011,7 +2011,6 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61
private final Set<String> seenIllegalAccess = Collections.newSetFromMap(new ConcurrentHashMap<>());
+ private java.util.logging.Logger logger; // Paper - add field
+ private io.papermc.paper.plugin.provider.classloader.PluginClassLoaderGroup classLoaderGroup; // Paper
+ public io.papermc.paper.plugin.provider.entrypoint.DependencyContext dependencyContext; // Paper
static {
ClassLoader.registerAsParallelCapable();
@ -2019,7 +2018,7 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61
- PluginClassLoader(@NotNull final JavaPluginLoader loader, @Nullable final ClassLoader parent, @NotNull final PluginDescriptionFile description, @NotNull final File dataFolder, @NotNull final File file, @Nullable ClassLoader libraryLoader) throws IOException, InvalidPluginException, MalformedURLException {
+ @org.jetbrains.annotations.ApiStatus.Internal // Paper
+ public PluginClassLoader(@Nullable final ClassLoader parent, @NotNull final PluginDescriptionFile description, @NotNull final File dataFolder, @NotNull final File file, @Nullable ClassLoader libraryLoader, io.papermc.paper.plugin.provider.entrypoint.DependencyContext dependencyContext) throws IOException, InvalidPluginException, MalformedURLException { // Paper
+ public PluginClassLoader(@Nullable final ClassLoader parent, @NotNull final PluginDescriptionFile description, @NotNull final File dataFolder, @NotNull final File file, @Nullable ClassLoader libraryLoader) throws IOException, InvalidPluginException, MalformedURLException { // Paper
super(new URL[] {file.toURI().toURL()}, parent);
- Preconditions.checkArgument(loader != null, "Loader cannot be null");
+ this.loader = null; // Paper - pass null into loader field
@ -2028,19 +2027,18 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61
this.description = description;
this.dataFolder = dataFolder;
this.file = file;
@@ -61,6 +65,11 @@ final class PluginClassLoader extends URLClassLoader {
@@ -61,6 +64,10 @@ final class PluginClassLoader extends URLClassLoader {
this.url = file.toURI().toURL();
this.libraryLoader = libraryLoader;
+
+ // Paper start
+ this.classLoaderGroup = io.papermc.paper.plugin.provider.classloader.PaperClassLoaderStorage.instance().registerSpigotGroup(this); // Paper
+ this.dependencyContext = dependencyContext;
+ // Paper end
try {
Class<?> jarClass;
try {
@@ -94,6 +103,22 @@ final class PluginClassLoader extends URLClassLoader {
@@ -94,6 +101,22 @@ final class PluginClassLoader extends URLClassLoader {
return findResources(name);
}
@ -2063,7 +2061,7 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61
@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
return loadClass0(name, resolve, true, true);
@@ -119,7 +144,7 @@ final class PluginClassLoader extends URLClassLoader {
@@ -119,26 +142,11 @@ final class PluginClassLoader extends URLClassLoader {
if (checkGlobal) {
// This ignores the libraries of other plugins, unless they are transitive dependencies.
@ -2072,24 +2070,27 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61
if (result != null) {
// If the class was loaded from a library instead of a PluginClassLoader, we can assume that its associated plugin is a transitive dependency and can therefore skip this check.
@@ -128,14 +153,14 @@ final class PluginClassLoader extends URLClassLoader {
if (provider != description
&& !seenIllegalAccess.contains(provider.getName())
- if (result.getClassLoader() instanceof PluginClassLoader) {
- PluginDescriptionFile provider = ((PluginClassLoader) result.getClassLoader()).description;
-
- if (provider != description
- && !seenIllegalAccess.contains(provider.getName())
- && !((SimplePluginManager) loader.server.getPluginManager()).isTransitiveDepend(description, provider)) {
+ && !this.dependencyContext.isTransitiveDependency(description, provider)) { // Paper
seenIllegalAccess.add(provider.getName());
if (plugin != null) {
plugin.getLogger().log(Level.WARNING, "Loaded class {0} from {1} which is not a depend or softdepend of this plugin.", new Object[]{name, provider.getFullName()});
} else {
// In case the bad access occurs on construction
-
- seenIllegalAccess.add(provider.getName());
- if (plugin != null) {
- plugin.getLogger().log(Level.WARNING, "Loaded class {0} from {1} which is not a depend or softdepend of this plugin.", new Object[]{name, provider.getFullName()});
- } else {
- // In case the bad access occurs on construction
- loader.server.getLogger().log(Level.WARNING, "[{0}] Loaded class {1} from {2} which is not a depend or softdepend of this plugin.", new Object[]{description.getName(), name, provider.getFullName()});
+ org.bukkit.Bukkit.getLogger().log(Level.WARNING, "[{0}] Loaded class {1} from {2} which is not a depend or softdepend of this plugin.", new Object[]{description.getName(), name, provider.getFullName()}); // Paper
}
}
}
@@ -167,7 +192,7 @@ final class PluginClassLoader extends URLClassLoader {
- }
- }
- }
+ // Paper - Totally delete the illegal access logic, we are never going to enforce it anyways here.
return result;
}
@@ -167,7 +175,7 @@ final class PluginClassLoader extends URLClassLoader {
throw new ClassNotFoundException(name, ex);
}
@ -2098,7 +2099,7 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61
int dot = name.lastIndexOf('.');
if (dot != -1) {
@@ -197,8 +222,8 @@ final class PluginClassLoader extends URLClassLoader {
@@ -197,8 +205,8 @@ final class PluginClassLoader extends URLClassLoader {
result = super.findClass(name);
}
@ -2108,7 +2109,7 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61
}
return result;
@@ -207,6 +232,12 @@ final class PluginClassLoader extends URLClassLoader {
@@ -207,6 +215,12 @@ final class PluginClassLoader extends URLClassLoader {
@Override
public void close() throws IOException {
try {
@ -2121,7 +2122,7 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61
super.close();
} finally {
jar.close();
@@ -218,7 +249,7 @@ final class PluginClassLoader extends URLClassLoader {
@@ -218,7 +232,7 @@ final class PluginClassLoader extends URLClassLoader {
return classes.values();
}
@ -2130,7 +2131,7 @@ index 2f74ec96ece706de23156ebabfe493211bc05391..2c3d2f60d3f2f55a1a90791d37521c61
Preconditions.checkArgument(javaPlugin != null, "Initializing plugin cannot be null");
Preconditions.checkArgument(javaPlugin.getClass().getClassLoader() == this, "Cannot initialize plugin outside of this class loader");
if (this.plugin != null || this.pluginInit != null) {
@@ -228,6 +259,32 @@ final class PluginClassLoader extends URLClassLoader {
@@ -228,6 +242,32 @@ final class PluginClassLoader extends URLClassLoader {
pluginState = new IllegalStateException("Initial initialization");
this.pluginInit = javaPlugin;

View file

@ -93,10 +93,10 @@ index 79df67daf2fe8193fd83dd6a7bfc78b3f6e524c2..0e4cedc005466c600ff6b9d500febf33
/**
diff --git a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
index c5f49ba2d0cc5cdf127670ea2be59f1b174dc94b..1c6542bb9ce13781c8f3b84330b5ef5aa52d0348 100644
index 845b3f8a7dedf801d45489e807ab971dcfe2382e..666f182e5cf2f07a2cf6a17b0d28a100b3f0b891 100644
--- a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
+++ b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
@@ -66,7 +66,7 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
@@ -65,7 +65,7 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
this.url = file.toURI().toURL();
this.libraryLoader = libraryLoader;
@ -104,8 +104,8 @@ index c5f49ba2d0cc5cdf127670ea2be59f1b174dc94b..1c6542bb9ce13781c8f3b84330b5ef5a
+ this.logger = com.destroystokyo.paper.utils.PaperPluginLogger.getLogger(description); // Paper - Register logger early
// Paper start
this.classLoaderGroup = io.papermc.paper.plugin.provider.classloader.PaperClassLoaderStorage.instance().registerSpigotGroup(this); // Paper
this.dependencyContext = dependencyContext;
@@ -260,6 +260,7 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
// Paper end
@@ -243,6 +243,7 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
pluginState = new IllegalStateException("Initial initialization");
this.pluginInit = javaPlugin;

View file

@ -5,10 +5,10 @@ Subject: [PATCH] Enable multi-release plugin jars
diff --git a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
index a657654079c40a0fee6f70c7d72df24b3827b911..ef60a8a7e20e27fee6f96fe1398ec9aee9352aec 100644
index 666f182e5cf2f07a2cf6a17b0d28a100b3f0b891..14cdd833bb56186e7cb83e035348f4dc942e4740 100644
--- a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
+++ b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
@@ -61,7 +61,7 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
@@ -60,7 +60,7 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
this.description = description;
this.dataFolder = dataFolder;
this.file = file;

View file

@ -5,13 +5,13 @@ Subject: [PATCH] Rewrite LogEvents to contain the source jars in stack traces
diff --git a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
index ef60a8a7e20e27fee6f96fe1398ec9aee9352aec..87c90128ada98fcb31ff106333ffabb35972a107 100644
index 14cdd833bb56186e7cb83e035348f4dc942e4740..9b4b81f70624cd3906c94cbab99aabe7f9a4223e 100644
--- a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
+++ b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
@@ -55,7 +55,7 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
@@ -54,7 +54,7 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
@org.jetbrains.annotations.ApiStatus.Internal // Paper
public PluginClassLoader(@Nullable final ClassLoader parent, @NotNull final PluginDescriptionFile description, @NotNull final File dataFolder, @NotNull final File file, @Nullable ClassLoader libraryLoader, io.papermc.paper.plugin.provider.entrypoint.DependencyContext dependencyContext) throws IOException, InvalidPluginException, MalformedURLException { // Paper
public PluginClassLoader(@Nullable final ClassLoader parent, @NotNull final PluginDescriptionFile description, @NotNull final File dataFolder, @NotNull final File file, @Nullable ClassLoader libraryLoader) throws IOException, InvalidPluginException, MalformedURLException { // Paper
- super(new URL[] {file.toURI().toURL()}, parent);
+ super(file.getName(), new URL[] {file.toURI().toURL()}, parent);
this.loader = null; // Paper - pass null into loader field

View file

@ -5,10 +5,10 @@ Subject: [PATCH] Also load resources from LibraryLoader
diff --git a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
index 87c90128ada98fcb31ff106333ffabb35972a107..4cb4e28c9b0dfdac45c4129fb0325e6afe5cb131 100644
index 9b4b81f70624cd3906c94cbab99aabe7f9a4223e..4666d29d27e6247422a94e99511a190ce9484f76 100644
--- a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
+++ b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
@@ -96,14 +96,35 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
@@ -94,14 +94,35 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
@Override
public URL getResource(String name) {

View file

@ -1,23 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Nassim Jahnke <nassim@njahnke.dev>
Date: Sat, 1 Oct 2022 09:44:26 +0200
Subject: [PATCH] Add system property to print stacktrace on bad plugin class
access
diff --git a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
index e9fbf5fd2c86150561468f2c061b75004b123952..e0e69b5639eeb424cb55b0be24a7e938e45fbb26 100644
--- a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
+++ b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
@@ -184,6 +184,11 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
// In case the bad access occurs on construction
org.bukkit.Bukkit.getLogger().log(Level.WARNING, "[{0}] Loaded class {1} from {2} which is not a depend or softdepend of this plugin.", new Object[]{description.getName(), name, provider.getFullName()}); // Paper
}
+ // Paper start
+ if (Boolean.getBoolean("Paper.printStacktraceOnBadPluginClassAccess")) {
+ (plugin != null ? plugin.getLogger() : org.bukkit.Bukkit.getLogger()).log(Level.WARNING, "Stacktrace", new Exception());
+ }
+ // Paper end
}
}

File diff suppressed because it is too large Load diff