From 9b0f4a241c764bd6b4bbef3abdfd08d54b5a8978 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Tue, 18 Jan 2022 11:47:54 -0700 Subject: [PATCH] Warn on strange @EventHandler return types (#7372) --- ...on-strange-EventHandler-return-types.patch | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 patches/api/Warn-on-strange-EventHandler-return-types.patch diff --git a/patches/api/Warn-on-strange-EventHandler-return-types.patch b/patches/api/Warn-on-strange-EventHandler-return-types.patch new file mode 100644 index 0000000000..588ba35f89 --- /dev/null +++ b/patches/api/Warn-on-strange-EventHandler-return-types.patch @@ -0,0 +1,23 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> +Date: Tue, 18 Jan 2022 11:07:54 -0700 +Subject: [PATCH] Warn on strange @EventHandler return types + + +diff --git a/src/main/java/org/bukkit/plugin/EventExecutor.java b/src/main/java/org/bukkit/plugin/EventExecutor.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/plugin/EventExecutor.java ++++ b/src/main/java/org/bukkit/plugin/EventExecutor.java +@@ -0,0 +0,0 @@ public interface EventExecutor { + Preconditions.checkArgument(m.getParameterCount() != 0, "Incorrect number of arguments %s", m.getParameterCount()); + Preconditions.checkArgument(m.getParameterTypes()[0] == eventClass, "First parameter %s doesn't match event class %s", m.getParameterTypes()[0], eventClass); + ClassDefiner definer = ClassDefiner.getInstance(); ++ if (m.getReturnType() != Void.TYPE) { ++ final org.bukkit.plugin.java.JavaPlugin plugin = org.bukkit.plugin.java.JavaPlugin.getProvidingPlugin(m.getDeclaringClass()); ++ org.bukkit.Bukkit.getLogger().warning("@EventHandler method " + m.getDeclaringClass().getName() + (Modifier.isStatic(m.getModifiers()) ? '.' : '#') + m.getName() ++ + " returns non-void type " + m.getReturnType().getName() + ". This is an unsupported behavior which will be removed in a future version of Paper." ++ + "This should be reported to the developers of " + plugin.getDescription().getFullName() + ", (" + String.join(",", plugin.getDescription().getAuthors()) + ')'); ++ } + if (Modifier.isStatic(m.getModifiers())) { + return new StaticMethodHandleEventExecutor(eventClass, m); + } else if (definer.isBypassAccessChecks() || Modifier.isPublic(m.getDeclaringClass().getModifiers()) && Modifier.isPublic(m.getModifiers())) {