mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-29 11:41:36 +01:00
Redefine Cyclic Dependencies (#8873)
This commit is contained in:
parent
1c5cb2f43a
commit
08d77ce67a
@ -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
|
||||
// Paper start
|
||||
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
|
||||
pluginState = new IllegalStateException("Initial initialization");
|
||||
this.pluginInit = javaPlugin;
|
||||
|
@ -1966,7 +1966,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
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) {
|
||||
@ -2011,7 +2011,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
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 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 {
|
||||
+ @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
|
||||
@ -2035,7 +2034,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+
|
||||
+ // Paper start
|
||||
+ this.classLoaderGroup = io.papermc.paper.plugin.provider.classloader.PaperClassLoaderStorage.instance().registerSpigotGroup(this); // Paper
|
||||
+ this.dependencyContext = dependencyContext;
|
||||
+ // Paper end
|
||||
try {
|
||||
Class<?> jarClass;
|
||||
@ -2072,23 +2070,26 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
|
||||
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.
|
||||
@@ -0,0 +0,0 @@ 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
|
||||
}
|
||||
}
|
||||
}
|
||||
- }
|
||||
- }
|
||||
- }
|
||||
+ // 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 {
|
||||
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
|
||||
|
||||
@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
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user