From d689ba590451b12566e4946ee7275b29e9fc0ffe Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 21 Dec 2018 10:15:36 +1100 Subject: [PATCH] #2535: Reduce verbosity of unhandled packet exception messages --- .../java/net/md_5/bungee/ServerConnector.java | 5 ++-- .../bungee/connection/InitialHandler.java | 3 ++- .../md_5/bungee/connection/PingHandler.java | 3 ++- .../net/md_5/bungee/netty/HandlerBoss.java | 7 ++++++ .../net/md_5/bungee/util/QuietException.java | 25 +++++++++++++++++++ 5 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 proxy/src/main/java/net/md_5/bungee/util/QuietException.java diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index 03b45d14b..177b73894 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -47,6 +47,7 @@ import net.md_5.bungee.protocol.packet.ScoreboardObjective; import net.md_5.bungee.protocol.packet.ScoreboardScore; import net.md_5.bungee.protocol.packet.SetCompression; import net.md_5.bungee.util.BufUtil; +import net.md_5.bungee.util.QuietException; @RequiredArgsConstructor public class ServerConnector extends PacketHandler @@ -128,7 +129,7 @@ public class ServerConnector extends PacketHandler { if ( packet.packet == null ) { - throw new IllegalArgumentException( "Unexpected packet received during server login process!\n" + BufUtil.dump( packet.buf, 64 ) ); + throw new QuietException( "Unexpected packet received during server login process!\n" + BufUtil.dump( packet.buf, 16 ) ); } } @@ -292,7 +293,7 @@ public class ServerConnector extends PacketHandler @Override public void handle(EncryptionRequest encryptionRequest) throws Exception { - throw new RuntimeException( "Server is online mode!" ); + throw new QuietException( "Server is online mode!" ); } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java index 34dd743ca..dbd77a358 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java @@ -64,6 +64,7 @@ import net.md_5.bungee.protocol.packet.StatusRequest; import net.md_5.bungee.protocol.packet.StatusResponse; import net.md_5.bungee.util.BoundedArrayList; import net.md_5.bungee.util.BufUtil; +import net.md_5.bungee.util.QuietException; @RequiredArgsConstructor public class InitialHandler extends PacketHandler implements PendingConnection @@ -134,7 +135,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection { if ( packet.packet == null ) { - throw new IllegalArgumentException( "Unexpected packet received during login process!\n" + BufUtil.dump( packet.buf, 64 ) ); + throw new QuietException( "Unexpected packet received during login process! " + BufUtil.dump( packet.buf, 16 ) ); } } diff --git a/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java index 76f496ce2..6bc14d675 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java @@ -19,6 +19,7 @@ import net.md_5.bungee.protocol.packet.Handshake; import net.md_5.bungee.protocol.packet.StatusRequest; import net.md_5.bungee.protocol.packet.StatusResponse; import net.md_5.bungee.util.BufUtil; +import net.md_5.bungee.util.QuietException; @RequiredArgsConstructor public class PingHandler extends PacketHandler @@ -55,7 +56,7 @@ public class PingHandler extends PacketHandler { if ( packet.packet == null ) { - throw new IllegalArgumentException( "Unexpected packet received during ping process!\n" + BufUtil.dump( packet.buf, 64 ) ); + throw new QuietException( "Unexpected packet received during ping process! " + BufUtil.dump( packet.buf, 16 ) ); } } diff --git a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java index 7e7cf7bed..a66099fc6 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java @@ -16,6 +16,7 @@ import net.md_5.bungee.connection.PingHandler; import net.md_5.bungee.protocol.BadPacketException; import net.md_5.bungee.protocol.OverflowPacketException; import net.md_5.bungee.protocol.PacketWrapper; +import net.md_5.bungee.util.QuietException; /** * This class is a primitive wrapper for {@link PacketHandler} instances tied to @@ -147,6 +148,12 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter { handler, cause.getClass().getSimpleName(), cause.getMessage() } ); + } else if ( cause instanceof QuietException ) + { + ProxyServer.getInstance().getLogger().log( Level.SEVERE, "{0} - encountered exception: {1}", new Object[] + { + handler, cause + } ); } else { ProxyServer.getInstance().getLogger().log( Level.SEVERE, handler + " - encountered exception", cause ); diff --git a/proxy/src/main/java/net/md_5/bungee/util/QuietException.java b/proxy/src/main/java/net/md_5/bungee/util/QuietException.java new file mode 100644 index 000000000..3c958fde0 --- /dev/null +++ b/proxy/src/main/java/net/md_5/bungee/util/QuietException.java @@ -0,0 +1,25 @@ +package net.md_5.bungee.util; + +/** + * Exception without a stack trace component. + */ +public class QuietException extends RuntimeException +{ + + public QuietException(String message) + { + super( message ); + } + + @Override + public Throwable initCause(Throwable cause) + { + return this; + } + + @Override + public Throwable fillInStackTrace() + { + return this; + } +}