From 06bf088d27214882ffaa6bcbe13f530d082a020c Mon Sep 17 00:00:00 2001 From: Janmm14 Date: Fri, 17 Sep 2021 18:14:21 +1000 Subject: [PATCH] #3186: Replace String.format calls in exceptions with simple string concats --- .../java/net/md_5/bungee/api/chat/TextComponent.java | 2 +- .../java/net/md_5/bungee/protocol/DefinedPacket.java | 10 +++++----- .../java/net/md_5/bungee/scheduler/BungeeTask.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/chat/src/main/java/net/md_5/bungee/api/chat/TextComponent.java b/chat/src/main/java/net/md_5/bungee/api/chat/TextComponent.java index 1598dcc5..8601793a 100644 --- a/chat/src/main/java/net/md_5/bungee/api/chat/TextComponent.java +++ b/chat/src/main/java/net/md_5/bungee/api/chat/TextComponent.java @@ -230,6 +230,6 @@ public final class TextComponent extends BaseComponent @Override public String toString() { - return String.format( "TextComponent{text=%s, %s}", text, super.toString() ); + return "TextComponent{text=" + text + ", " + super.toString() + '}'; } } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java index 0cef9430..8b2a2822 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java @@ -23,7 +23,7 @@ public abstract class DefinedPacket { if ( s.length() > Short.MAX_VALUE ) { - throw new OverflowPacketException( String.format( "Cannot send string longer than Short.MAX_VALUE (got %s characters)", s.length() ) ); + throw new OverflowPacketException( "Cannot send string longer than Short.MAX_VALUE (got " + s.length() + " characters)" ); } byte[] b = s.getBytes( Charsets.UTF_8 ); @@ -41,7 +41,7 @@ public abstract class DefinedPacket int len = readVarInt( buf ); if ( len > maxLen * 4 ) { - throw new OverflowPacketException( String.format( "Cannot receive string longer than %d (got %d bytes)", maxLen * 4, len ) ); + throw new OverflowPacketException( "Cannot receive string longer than " + maxLen * 4 + " (got " + len + " bytes)" ); } byte[] b = new byte[ len ]; @@ -50,7 +50,7 @@ public abstract class DefinedPacket String s = new String( b, Charsets.UTF_8 ); if ( s.length() > maxLen ) { - throw new OverflowPacketException( String.format( "Cannot receive string longer than %d (got %d characters)", maxLen, s.length() ) ); + throw new OverflowPacketException( "Cannot receive string longer than " + maxLen + " (got " + s.length() + " characters)" ); } return s; @@ -60,7 +60,7 @@ public abstract class DefinedPacket { if ( b.length > Short.MAX_VALUE ) { - throw new OverflowPacketException( String.format( "Cannot send byte array longer than Short.MAX_VALUE (got %s bytes)", b.length ) ); + throw new OverflowPacketException( "Cannot send byte array longer than Short.MAX_VALUE (got " + b.length + " bytes)" ); } writeVarInt( b.length, buf ); buf.writeBytes( b ); @@ -84,7 +84,7 @@ public abstract class DefinedPacket int len = readVarInt( buf ); if ( len > limit ) { - throw new OverflowPacketException( String.format( "Cannot receive byte array longer than %s (got %s bytes)", limit, len ) ); + throw new OverflowPacketException( "Cannot receive byte array longer than " + limit + " (got " + len + " bytes)" ); } byte[] ret = new byte[ len ]; buf.readBytes( ret ); diff --git a/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeTask.java b/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeTask.java index 67db0cc4..38b75b51 100644 --- a/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeTask.java +++ b/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeTask.java @@ -63,7 +63,7 @@ public class BungeeTask implements Runnable, ScheduledTask task.run(); } catch ( Throwable t ) { - ProxyServer.getInstance().getLogger().log( Level.SEVERE, String.format( "Task %s encountered an exception", this ), t ); + ProxyServer.getInstance().getLogger().log( Level.SEVERE, "Task " + this + " encountered an exception", t ); } // If we have a period of 0 or less, only run once