mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-01 12:42:05 -07:00
Redefine Cyclic Dependencies (#8873)
This commit is contained in:
@@ -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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
||||||
--- a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
|
|
||||||
+++ b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
|
|
||||||
@@ -0,0 +0,0 @@ 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@@ -104,7 +104,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ this.logger = com.destroystokyo.paper.utils.PaperPluginLogger.getLogger(description); // Paper - Register logger early
|
+ this.logger = com.destroystokyo.paper.utils.PaperPluginLogger.getLogger(description); // Paper - Register logger early
|
||||||
// Paper start
|
// Paper start
|
||||||
this.classLoaderGroup = io.papermc.paper.plugin.provider.classloader.PaperClassLoaderStorage.instance().registerSpigotGroup(this); // Paper
|
this.classLoaderGroup = io.papermc.paper.plugin.provider.classloader.PaperClassLoaderStorage.instance().registerSpigotGroup(this); // Paper
|
||||||
this.dependencyContext = dependencyContext;
|
// Paper end
|
||||||
@@ -0,0 +0,0 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
|
@@ -0,0 +0,0 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
|
||||||
pluginState = new IllegalStateException("Initial initialization");
|
pluginState = new IllegalStateException("Initial initialization");
|
||||||
this.pluginInit = javaPlugin;
|
this.pluginInit = javaPlugin;
|
||||||
|
@@ -1966,7 +1966,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
final PluginClassLoader loader;
|
final PluginClassLoader loader;
|
||||||
try {
|
try {
|
||||||
- loader = new PluginClassLoader(this, getClass().getClassLoader(), description, dataFolder, file, (libraryLoader != null) ? libraryLoader.createLoader(description) : null);
|
- 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) {
|
} catch (InvalidPluginException ex) {
|
||||||
throw ex;
|
throw ex;
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
@@ -2011,7 +2011,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
private final Set<String> seenIllegalAccess = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
private final Set<String> seenIllegalAccess = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||||
+ private java.util.logging.Logger logger; // Paper - add field
|
+ private java.util.logging.Logger logger; // Paper - add field
|
||||||
+ private io.papermc.paper.plugin.provider.classloader.PluginClassLoaderGroup classLoaderGroup; // Paper
|
+ private io.papermc.paper.plugin.provider.classloader.PluginClassLoaderGroup classLoaderGroup; // Paper
|
||||||
+ public io.papermc.paper.plugin.provider.entrypoint.DependencyContext dependencyContext; // Paper
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ClassLoader.registerAsParallelCapable();
|
ClassLoader.registerAsParallelCapable();
|
||||||
@@ -2019,7 +2018,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
|
|
||||||
- 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 {
|
- 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
|
+ @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(new URL[] {file.toURI().toURL()}, parent);
|
||||||
- Preconditions.checkArgument(loader != null, "Loader cannot be null");
|
- Preconditions.checkArgument(loader != null, "Loader cannot be null");
|
||||||
+ this.loader = null; // Paper - pass null into loader field
|
+ this.loader = null; // Paper - pass null into loader field
|
||||||
@@ -2035,7 +2034,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+
|
+
|
||||||
+ // Paper start
|
+ // Paper start
|
||||||
+ this.classLoaderGroup = io.papermc.paper.plugin.provider.classloader.PaperClassLoaderStorage.instance().registerSpigotGroup(this); // Paper
|
+ this.classLoaderGroup = io.papermc.paper.plugin.provider.classloader.PaperClassLoaderStorage.instance().registerSpigotGroup(this); // Paper
|
||||||
+ this.dependencyContext = dependencyContext;
|
|
||||||
+ // Paper end
|
+ // Paper end
|
||||||
try {
|
try {
|
||||||
Class<?> jarClass;
|
Class<?> jarClass;
|
||||||
@@ -2072,23 +2070,26 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
|
|
||||||
if (result != null) {
|
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.
|
// 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.
|
||||||
@@ -0,0 +0,0 @@ final class PluginClassLoader extends URLClassLoader {
|
- if (result.getClassLoader() instanceof PluginClassLoader) {
|
||||||
|
- PluginDescriptionFile provider = ((PluginClassLoader) result.getClassLoader()).description;
|
||||||
if (provider != description
|
-
|
||||||
&& !seenIllegalAccess.contains(provider.getName())
|
- if (provider != description
|
||||||
|
- && !seenIllegalAccess.contains(provider.getName())
|
||||||
- && !((SimplePluginManager) loader.server.getPluginManager()).isTransitiveDepend(description, provider)) {
|
- && !((SimplePluginManager) loader.server.getPluginManager()).isTransitiveDepend(description, provider)) {
|
||||||
+ && !this.dependencyContext.isTransitiveDependency(description, provider)) { // Paper
|
-
|
||||||
|
- seenIllegalAccess.add(provider.getName());
|
||||||
seenIllegalAccess.add(provider.getName());
|
- if (plugin != null) {
|
||||||
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()});
|
||||||
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 {
|
||||||
} else {
|
- // In case the bad access occurs on construction
|
||||||
// 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()});
|
- 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
|
- }
|
||||||
}
|
- }
|
||||||
}
|
- }
|
||||||
}
|
+ // Paper - Totally delete the illegal access logic, we are never going to enforce it anyways here.
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -0,0 +0,0 @@ final class PluginClassLoader extends URLClassLoader {
|
@@ -0,0 +0,0 @@ final class PluginClassLoader extends URLClassLoader {
|
||||||
throw new ClassNotFoundException(name, ex);
|
throw new ClassNotFoundException(name, ex);
|
||||||
}
|
}
|
||||||
|
@@ -11,7 +11,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
@@ -0,0 +0,0 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
|
@@ -0,0 +0,0 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
|
||||||
|
|
||||||
@org.jetbrains.annotations.ApiStatus.Internal // Paper
|
@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(new URL[] {file.toURI().toURL()}, parent);
|
||||||
+ super(file.getName(), new URL[] {file.toURI().toURL()}, parent);
|
+ super(file.getName(), new URL[] {file.toURI().toURL()}, parent);
|
||||||
this.loader = null; // Paper - pass null into loader field
|
this.loader = null; // Paper - pass null into loader field
|
||||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user