From 19bb8f72c70a2f55a6239ab92cf3a1909bff3582 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 12 Jul 2014 13:33:13 +1000 Subject: [PATCH] Fix some static analysis warnings. --- .../src/main/java/net/md_5/bungee/BungeeCord.java | 15 ++++++++------- .../main/java/net/md_5/bungee/EncryptionUtil.java | 2 +- .../main/java/net/md_5/bungee/UserConnection.java | 6 +++++- .../java/net/md_5/bungee/conf/Configuration.java | 2 ++ .../java/net/md_5/bungee/http/HttpClient.java | 1 + .../java/net/md_5/bungee/log/BungeeLogger.java | 4 ++++ .../net/md_5/bungee/log/ConciseFormatter.java | 1 + .../java/net/md_5/bungee/netty/HandlerBoss.java | 9 ++++++--- .../src/main/java/net/md_5/bungee/tab/Custom.java | 4 ++-- .../main/java/net/md_5/bungee/tab/GlobalPing.java | 1 - 10 files changed, 30 insertions(+), 15 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index 0a3900f82..5a2580462 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -104,7 +104,7 @@ public class BungeeCord extends ProxyServer /** * Server socket listener. */ - private Collection listeners = new HashSet<>(); + private final Collection listeners = new HashSet<>(); /** * Fully qualified connections. */ @@ -127,7 +127,7 @@ public class BungeeCord extends ProxyServer @Getter private final BungeeScheduler scheduler = new BungeeScheduler(); @Getter - private ConsoleReader consoleReader; + private final ConsoleReader consoleReader; @Getter private final Logger logger; public final Gson gson = new GsonBuilder() @@ -251,7 +251,7 @@ public class BungeeCord extends ProxyServer if ( future.isSuccess() ) { listeners.add( future.channel() ); - getLogger().info( "Listening on " + info.getHost() ); + getLogger().log( Level.INFO, "Listening on {0}", info.getHost() ); } else { getLogger().log( Level.WARNING, "Could not bind to host " + info.getHost(), future.cause() ); @@ -277,7 +277,7 @@ public class BungeeCord extends ProxyServer if ( future.isSuccess() ) { listeners.add( future.channel() ); - getLogger().info( "Started query on " + future.channel().localAddress() ); + getLogger().log( Level.INFO, "Started query on {0}", future.channel().localAddress() ); } else { getLogger().log( Level.WARNING, "Could not bind to host " + info.getHost(), future.cause() ); @@ -311,6 +311,7 @@ public class BungeeCord extends ProxyServer new Thread( "Shutdown Thread" ) { @Override + @SuppressWarnings("TooBroadCatch") public void run() { BungeeCord.this.isRunning = false; @@ -321,7 +322,7 @@ public class BungeeCord extends ProxyServer connectionLock.readLock().lock(); try { - getLogger().info( "Disconnecting " + connections.size() + " connections" ); + getLogger().log( Level.INFO, "Disconnecting {0} connections", connections.size() ); for ( UserConnection user : connections.values() ) { user.disconnect( getTranslation( "restart" ) ); @@ -362,8 +363,7 @@ public class BungeeCord extends ProxyServer } } catch ( Throwable t ) { - getLogger().severe( "Exception disabling plugin " + plugin.getDescription().getName() ); - t.printStackTrace(); + getLogger().log( Level.SEVERE, "Exception disabling plugin " + plugin.getDescription().getName(), t ); } getScheduler().cancel( plugin ); plugin.getExecutorService().shutdownNow(); @@ -458,6 +458,7 @@ public class BungeeCord extends ProxyServer } } + @Override public ProxiedPlayer getPlayer(UUID uuid) { connectionLock.readLock().lock(); diff --git a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java index dabff27c1..50520b467 100644 --- a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java +++ b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java @@ -26,7 +26,7 @@ public class EncryptionUtil private static final Random random = new Random(); public static KeyPair keys; @Getter - private static SecretKey secret = new SecretKeySpec( new byte[ 16 ], "AES" ); + private static final SecretKey secret = new SecretKeySpec( new byte[ 16 ], "AES" ); static { diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index 10e732e66..62697e3a3 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -229,6 +229,7 @@ public final class UserConnection implements ProxiedPlayer ChannelFutureListener listener = new ChannelFutureListener() { @Override + @SuppressWarnings("ThrowableResultIgnored") public void operationComplete(ChannelFuture future) throws Exception { if ( callback != null ) @@ -295,7 +296,10 @@ public final class UserConnection implements ProxiedPlayer { if ( ch.getHandle().isActive() ) { - bungee.getLogger().log( Level.INFO, "[" + getName() + "] disconnected with: " + BaseComponent.toLegacyText( reason ) ); + bungee.getLogger().log( Level.INFO, "[{0}] disconnected with: {1}", new Object[] + { + getName(), BaseComponent.toLegacyText( reason ) + } ); unsafe().sendPacket( new Kick( ComponentSerializer.toString( reason ) ) ); ch.close(); if ( server != null ) diff --git a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java index 6394c6920..6e78b0eb6 100644 --- a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java +++ b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java @@ -120,12 +120,14 @@ public class Configuration implements ProxyConfig } } + @Override @Deprecated public String getFavicon() { return getFaviconObject().getEncoded(); } + @Override public Favicon getFaviconObject() { return favicon; diff --git a/proxy/src/main/java/net/md_5/bungee/http/HttpClient.java b/proxy/src/main/java/net/md_5/bungee/http/HttpClient.java index c8e4af867..f8755e5ef 100644 --- a/proxy/src/main/java/net/md_5/bungee/http/HttpClient.java +++ b/proxy/src/main/java/net/md_5/bungee/http/HttpClient.java @@ -29,6 +29,7 @@ public class HttpClient public static final int TIMEOUT = 5000; private static final Cache addressCache = CacheBuilder.newBuilder().expireAfterWrite( 5, TimeUnit.MINUTES ).build(); + @SuppressWarnings("UnusedAssignment") public static void get(String url, EventLoop eventLoop, final Callback callback) { Preconditions.checkNotNull( url, "url" ); diff --git a/proxy/src/main/java/net/md_5/bungee/log/BungeeLogger.java b/proxy/src/main/java/net/md_5/bungee/log/BungeeLogger.java index f29f14b44..90b4c01c9 100644 --- a/proxy/src/main/java/net/md_5/bungee/log/BungeeLogger.java +++ b/proxy/src/main/java/net/md_5/bungee/log/BungeeLogger.java @@ -14,6 +14,10 @@ public class BungeeLogger extends Logger private final Formatter formatter = new ConciseFormatter(); private final LogDispatcher dispatcher = new LogDispatcher( this ); + @SuppressWarnings( + { + "CallToPrintStackTrace", "CallToThreadStartDuringObjectConstruction" + }) public BungeeLogger(BungeeCord bungee) { super( "BungeeCord", null ); diff --git a/proxy/src/main/java/net/md_5/bungee/log/ConciseFormatter.java b/proxy/src/main/java/net/md_5/bungee/log/ConciseFormatter.java index 6e0ddd86c..015a47169 100644 --- a/proxy/src/main/java/net/md_5/bungee/log/ConciseFormatter.java +++ b/proxy/src/main/java/net/md_5/bungee/log/ConciseFormatter.java @@ -13,6 +13,7 @@ public class ConciseFormatter extends Formatter private final DateFormat date = new SimpleDateFormat( System.getProperty( "net.md_5.bungee.log-date-format", "HH:mm:ss" ) ); @Override + @SuppressWarnings("ThrowableResultIgnored") public String format(LogRecord record) { StringBuilder formatted = new StringBuilder(); 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 fc80d1694..d775f398c 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 @@ -96,13 +96,16 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter { if ( cause instanceof ReadTimeoutException ) { - ProxyServer.getInstance().getLogger().log( Level.WARNING, handler + " - read timed out" ); + ProxyServer.getInstance().getLogger().log( Level.WARNING, "{0} - read timed out", handler ); } else if ( cause instanceof BadPacketException ) { - ProxyServer.getInstance().getLogger().log( Level.WARNING, handler + " - bad packet ID, are mods in use!?" ); + ProxyServer.getInstance().getLogger().log( Level.WARNING, "{0} - bad packet ID, are mods in use!?", handler ); } else if ( cause instanceof IOException ) { - ProxyServer.getInstance().getLogger().log( Level.WARNING, handler + " - IOException: " + cause.getMessage() ); + ProxyServer.getInstance().getLogger().log( Level.WARNING, "{0} - IOException: {1}", new Object[] + { + handler, cause.getMessage() + } ); } else { ProxyServer.getInstance().getLogger().log( Level.SEVERE, handler + " - encountered exception", cause ); diff --git a/proxy/src/main/java/net/md_5/bungee/tab/Custom.java b/proxy/src/main/java/net/md_5/bungee/tab/Custom.java index 902d2cf6c..e90b71f92 100644 --- a/proxy/src/main/java/net/md_5/bungee/tab/Custom.java +++ b/proxy/src/main/java/net/md_5/bungee/tab/Custom.java @@ -22,8 +22,8 @@ public class Custom extends TabListAdapter implements CustomTabList /*========================================================================*/ private final Collection sentStuff = new HashSet<>(); /*========================================================================*/ - private String[][] sent = new String[ ROWS ][ COLUMNS ]; - private String[][] slots = new String[ ROWS ][ COLUMNS ]; + private final String[][] sent = new String[ ROWS ][ COLUMNS ]; + private final String[][] slots = new String[ ROWS ][ COLUMNS ]; private int rowLim; private int colLim; diff --git a/proxy/src/main/java/net/md_5/bungee/tab/GlobalPing.java b/proxy/src/main/java/net/md_5/bungee/tab/GlobalPing.java index 0c6a1169d..da87014be 100644 --- a/proxy/src/main/java/net/md_5/bungee/tab/GlobalPing.java +++ b/proxy/src/main/java/net/md_5/bungee/tab/GlobalPing.java @@ -1,7 +1,6 @@ package net.md_5.bungee.tab; import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.protocol.packet.PlayerListItem; public class GlobalPing extends Global