From 5ca29ef5ceb9a4f0e5f6d2a0b96cd62e0116b10b Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Sun, 14 Apr 2013 03:53:27 +0200 Subject: [PATCH] Leave ThreadDead alone! The original intent of catching throwable is to "sandbox" arbitrary plugin logic and prevent it from ever accidentally killing threads on the server. A LinkageError due to a missing or old dependency shouldn't bring down the server, so we secure it by catching all exceptions around plugin event handlers. Trouble is, this also catches exceptions such as OutOfMemoryError or ThreadDead, which assuredly should NOT be caught. The latter case has even occured in the wild as seen by ticket 45 of TagAPI on BukkitDev. Minecraft may terminate the reader and writer thread by calling stop(), and this could occur within the event handler in a plugin. So we should let ThreadDead go and propagate it to the appropriate handler in Minecraft. --- .../injector/SortedPacketListenerList.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/SortedPacketListenerList.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/SortedPacketListenerList.java index e1e3d912..5391a948 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/SortedPacketListenerList.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/SortedPacketListenerList.java @@ -52,6 +52,11 @@ public final class SortedPacketListenerList extends AbstractConcurrentListenerMu try { event.setReadOnly(element.getPriority() == ListenerPriority.MONITOR); element.getListener().onPacketReceiving(event); + + } catch (OutOfMemoryError e) { + throw e; + } catch (ThreadDeath e) { + throw e; } catch (Throwable e) { // Minecraft doesn't want your Exception. reporter.reportMinimal(element.getListener().getPlugin(), "onPacketReceiving(PacketEvent)", e, @@ -78,6 +83,11 @@ public final class SortedPacketListenerList extends AbstractConcurrentListenerMu event.setReadOnly(element.getPriority() == ListenerPriority.MONITOR); element.getListener().onPacketReceiving(event); } + + } catch (OutOfMemoryError e) { + throw e; + } catch (ThreadDeath e) { + throw e; } catch (Throwable e) { // Minecraft doesn't want your Exception. reporter.reportMinimal(element.getListener().getPlugin(), "onPacketReceiving(PacketEvent)", e, @@ -101,6 +111,11 @@ public final class SortedPacketListenerList extends AbstractConcurrentListenerMu try { event.setReadOnly(element.getPriority() == ListenerPriority.MONITOR); element.getListener().onPacketSending(event); + + } catch (OutOfMemoryError e) { + throw e; + } catch (ThreadDeath e) { + throw e; } catch (Throwable e) { // Minecraft doesn't want your Exception. reporter.reportMinimal(element.getListener().getPlugin(), "onPacketSending(PacketEvent)", e, @@ -127,6 +142,11 @@ public final class SortedPacketListenerList extends AbstractConcurrentListenerMu event.setReadOnly(element.getPriority() == ListenerPriority.MONITOR); element.getListener().onPacketSending(event); } + + } catch (OutOfMemoryError e) { + throw e; + } catch (ThreadDeath e) { + throw e; } catch (Throwable e) { // Minecraft doesn't want your Exception. reporter.reportMinimal(element.getListener().getPlugin(), "onPacketSending(PacketEvent)", e,