From ae34a06a5f3aecba933fb0ce8f683359cef81367 Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 28 Jun 2019 14:36:58 +0700 Subject: [PATCH] [FIX] IDEA Code Inspect --- .../src/main/java/pro/gravit/launchserver/LaunchServer.java | 6 ------ .../pro/gravit/launchserver/asm/ClassMetadataReader.java | 2 +- .../launchserver/binary/tasks/AdditionalFixesApplyTask.java | 2 +- .../launchserver/command/dump/DumpEntryCacheCommand.java | 4 ++-- .../launchserver/command/dump/DumpSessionsCommand.java | 2 +- .../pro/gravit/launchserver/websocket/WebSocketService.java | 1 - .../websocket/fileserver/FileServerHandler.java | 1 - .../src/main/java/pro/gravit/launcher/LauncherAgent.java | 4 ++-- .../gravit/launcher/request/websockets/ClientJSONPoint.java | 2 +- .../request/websockets/StandartClientWebSocketService.java | 3 +-- .../main/java/pro/gravit/launcher/server/ServerAgent.java | 2 +- .../gravit/launcher/server/setup/ServerWrapperSetup.java | 2 +- 12 files changed, 11 insertions(+), 20 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index 1dc4f34c..67cedd26 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -954,9 +954,6 @@ public void registerObject(String name, Object object) { if (object instanceof NeedGarbageCollection) { GarbageManager.registerNeedGC((NeedGarbageCollection) object); } - if (object instanceof JsonConfigurable) { - - } } public void unregisterObject(String name, Object object) { @@ -969,9 +966,6 @@ public void unregisterObject(String name, Object object) { if (object instanceof NeedGarbageCollection) { GarbageManager.unregisterNeedGC((NeedGarbageCollection) object); } - if (object instanceof JsonConfigurable) { - - } } public void fullyRestart() { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ClassMetadataReader.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ClassMetadataReader.java index d6865874..d347dea7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ClassMetadataReader.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/ClassMetadataReader.java @@ -59,7 +59,7 @@ public void acceptVisitor(String className, ClassVisitor visitor) throws IOExcep public byte[] getClassData(String className) throws IOException { for (JarFile f : cp) { if (f.getEntry(className + ".class") != null) { - byte[] bytes = null; + byte[] bytes; try (InputStream in = f.getInputStream(f.getEntry(className + ".class"))) { bytes = IOHelper.read(in); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java index 0ad88cbd..bae3a847 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/AdditionalFixesApplyTask.java @@ -68,7 +68,7 @@ public static void apply(Path inputFile, Path addFile, ZipOutputStream output, L String filename = e.getName(); output.putNextEntry(IOHelper.newZipEntry(e)); if (filename.endsWith(".class")) { - byte[] bytes = null; + byte[] bytes; try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048)) { IOHelper.transfer(input, outputStream); bytes = outputStream.toByteArray(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dump/DumpEntryCacheCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dump/DumpEntryCacheCommand.java index bd133cb7..4fe70d76 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dump/DumpEntryCacheCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dump/DumpEntryCacheCommand.java @@ -50,8 +50,8 @@ public void invoke(String... args) throws Exception { LogHelper.subInfo("Write %d entryCache, %d usernameCache", entryCache.size(), usernamesCache.size()); } else if (args[0].equals("load")) { LogHelper.info("CachedAuthHandler read from %s", args[1]); - int size_entry = 0; - int size_username = 0; + int size_entry; + int size_username; try (Reader reader = IOHelper.newReader(Paths.get(args[1]))) { EntryAndUsername entryAndUsername = Launcher.gsonManager.configGson.fromJson(reader, EntryAndUsername.class); size_entry = entryAndUsername.entryCache.size(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dump/DumpSessionsCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dump/DumpSessionsCommand.java index 17c816a2..234b72d2 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dump/DumpSessionsCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dump/DumpSessionsCommand.java @@ -43,7 +43,7 @@ public void invoke(String... args) throws Exception { LogHelper.subInfo("Write %d sessions", clientSet.size()); } else if (args[0].equals("load")) { LogHelper.info("Sessions read from %s", args[1]); - int size = 0; + int size; try (Reader reader = IOHelper.newReader(Paths.get(args[1]))) { Type setType = new TypeToken>() { }.getType(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/WebSocketService.java b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/WebSocketService.java index 4ff1fe56..034c4732 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/WebSocketService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/WebSocketService.java @@ -69,7 +69,6 @@ public WebSocketService(ChannelGroup channels, LaunchServer server, GsonBuilder private final Gson gson; private final GsonBuilder gsonBuiler; - @SuppressWarnings("unchecked") void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client, String ip) { String request = frame.text(); JsonResponseInterface response = gson.fromJson(request, JsonResponseInterface.class); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/fileserver/FileServerHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/fileserver/FileServerHandler.java index 290b745d..a058581a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/fileserver/FileServerHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/websocket/fileserver/FileServerHandler.java @@ -46,7 +46,6 @@ import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpUtil; import io.netty.handler.codec.http.LastHttpContent; -import io.netty.handler.ssl.SslHandler; import io.netty.handler.stream.ChunkedFile; import io.netty.util.CharsetUtil; diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java index 05581b5e..4a4329a1 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java @@ -55,7 +55,7 @@ public static void premain(String agentArgument, Instrumentation instrumentation if (trimmedArg.contains("r")) rt = false; } } - if (System.getProperty("java.vm.name").toUpperCase(Locale.US).indexOf("HOTSPOT") != -1) + if (System.getProperty("java.vm.name").toUpperCase(Locale.US).contains("HOTSPOT")) try { if (ManagementFactory.getOperatingSystemMXBean().getName().startsWith("Windows")) replaceClasses(pb, rt); else replaceClasses(false, false); @@ -170,7 +170,7 @@ private static byte[] transformClass(String className, byte[] classBytes) { private static byte[] getClassFile(Class clazz) throws IOException { try (InputStream is = clazz.getResourceAsStream("/" + clazz.getName().replace('.', '/') + ".class"); ByteArrayOutputStream baos = new ByteArrayOutputStream()) { - int r = 0; + int r; byte[] buffer = new byte[8192]; while ((r = is.read(buffer)) >= 0) { baos.write(buffer, 0, r); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java index db4506b1..7451afa8 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java @@ -33,7 +33,7 @@ public abstract class ClientJSONPoint { protected WebSocketClientHandler webSocketClientHandler; protected Bootstrap bootstrap = new Bootstrap(); protected boolean ssl = false; - protected int port = -1; + protected int port; public boolean isClosed; public ClientJSONPoint(final String uri) throws SSLException { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java index aa34cd00..e2866a07 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java @@ -111,8 +111,7 @@ public static StandartClientWebSocketService initWebSockets(String address, bool try { service = new StandartClientWebSocketService(CommonHelper.newBuilder(), address, 5000); } catch (SSLException e) { - LogHelper.error(e); - return null; + throw new SecurityException(e); } service.registerResults(); service.registerRequests(); diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerAgent.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerAgent.java index 449b1f71..40113014 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerAgent.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerAgent.java @@ -63,7 +63,7 @@ public static void premain(String agentArgument, Instrumentation instrumentation proxyClass = Class.forName(proxyClassName); MethodHandle mainMethod = MethodHandles.publicLookup().findStatic(proxyClass, "premain", MethodType.methodType(void.class, String.class, Instrumentation.class)); Object[] args = {agentArgument, instrumentation}; - mainMethod.invoke(args); + mainMethod.invoke(null, args); } catch (Throwable e) { LogHelper.error(e); } diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java index ed2b5c8d..ad6c0174 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java @@ -23,7 +23,7 @@ public void run() throws IOException { System.out.println("Print jar filename:"); String jarName = commands.commandHandler.readLine(); Path jarPath = Paths.get(jarName); - String mainClassName = null; + String mainClassName; try (JarFile file = new JarFile(jarPath.toFile())) { URL jarURL = jarPath.toUri().toURL(); urlClassLoader = new PublicURLClassLoader(new URL[]{jarURL});