diff --git a/LaunchServer/source/auth/handler/TextFileAuthHandler.java b/LaunchServer/source/auth/handler/TextFileAuthHandler.java index b941e59..97f6849 100644 --- a/LaunchServer/source/auth/handler/TextFileAuthHandler.java +++ b/LaunchServer/source/auth/handler/TextFileAuthHandler.java @@ -9,6 +9,7 @@ import java.util.UUID; import launcher.helper.IOHelper; +import launcher.helper.VerifyHelper; import launcher.serialize.config.TextConfigReader; import launcher.serialize.config.TextConfigWriter; import launcher.serialize.config.entry.BlockConfigEntry; @@ -31,10 +32,8 @@ Set>> entrySet = authFile.getValue().entrySet(); for (Map.Entry> entry : entrySet) { UUID uuid = UUID.fromString(entry.getKey()); - ConfigEntry value = entry.getValue(); - if (value.getType() != ConfigEntry.Type.BLOCK) { - throw new IOException("Unsupported config entry type: " + uuid); - } + ConfigEntry value = VerifyHelper.verify(entry.getValue(), + v -> v.getType() == ConfigEntry.Type.BLOCK, "Illegal config entry type: " + uuid); // Get auth entry data BlockConfigEntry authBlock = (BlockConfigEntry) value; diff --git a/LaunchServer/source/auth/provider/FileAuthProvider.java b/LaunchServer/source/auth/provider/FileAuthProvider.java index f8eda3a..a9e3feb 100644 --- a/LaunchServer/source/auth/provider/FileAuthProvider.java +++ b/LaunchServer/source/auth/provider/FileAuthProvider.java @@ -9,6 +9,7 @@ import launcher.helper.IOHelper; import launcher.helper.LogHelper; +import launcher.helper.VerifyHelper; import launcher.serialize.config.entry.BlockConfigEntry; import launcher.serialize.config.entry.StringConfigEntry; import launchserver.helper.LineReader; @@ -54,22 +55,18 @@ try (BufferedReader reader = new LineReader(IOHelper.newReader(file))) { for (String line = reader.readLine(); line != null; line = reader.readLine()) { // Get and verify split index - int splitIndex = line.indexOf(':'); - if (splitIndex < 0) { - throw new IOException(String.format("Illegal line in users file: '%s'", line)); - } + int splitIndex = VerifyHelper.verifyInt(line.indexOf(':'), VerifyHelper.NOT_NEGATIVE, + String.format("Illegal line in users file: '%s'", line)); // Split and verify username and password - String username = line.substring(0, splitIndex).trim(); - String password = line.substring(splitIndex + 1).trim(); - if (username.isEmpty() || password.isEmpty()) { - throw new IOException(String.format("Empty username or password in users file: '%s'", line)); - } + String username = VerifyHelper.verify(line.substring(0, splitIndex).trim(), + VerifyHelper.NOT_EMPTY, "Empty username"); + String password = VerifyHelper.verify(line.substring(splitIndex + 1).trim(), + VerifyHelper.NOT_EMPTY, "Empty pasword"); // Try put to cache - if (cache.put(username, password) != null) { - throw new IOException(String.format("Duplicate username in users file: '%s'", username)); - } + VerifyHelper.putIfAbsent(cache, username, password, + String.format("Duplicate username in users file: '%s'", username)); } } diff --git a/LaunchServer/source/response/ServerSocketHandler.java b/LaunchServer/source/response/ServerSocketHandler.java index 8504e29..e1db91b 100644 --- a/LaunchServer/source/response/ServerSocketHandler.java +++ b/LaunchServer/source/response/ServerSocketHandler.java @@ -57,7 +57,7 @@ LogHelper.info("Starting server socket thread"); try (ServerSocket serverSocket = new ServerSocket()) { if (!this.serverSocket.compareAndSet(null, serverSocket)) { - throw new IOException("Previous socket wasn'sizet closed"); + throw new IllegalStateException("Previous socket wasn't closed"); } // Set socket params @@ -88,10 +88,8 @@ @LauncherAPI public Response newCustomResponse(String name, HInput input, HOutput output) throws IOException { - Response.Factory factory = customResponses.get(name); - if (factory == null) { - throw new IOException(String.format("Unknown custom response: '%s'", name)); - } + Response.Factory factory = VerifyHelper.getMapValue(customResponses, name, + String.format("Unknown custom response: '%s'", name)); return factory.newResponse(server, input, output); } diff --git a/Launcher/source/hasher/DirWatcher.java b/Launcher/source/hasher/DirWatcher.java index 07adbe0..32ae5a7 100644 --- a/Launcher/source/hasher/DirWatcher.java +++ b/Launcher/source/hasher/DirWatcher.java @@ -99,7 +99,8 @@ } // Forbidden modification! - throw new SecurityException(String.format("Forbidden modification (%s, %d times): '%s'", kind, event.count(), path)); + throw new SecurityException(String.format("Forbidden modification (%s, %d times): '%s'", + kind, event.count(), path)); } key.reset(); } diff --git a/Launcher/source/hasher/HashedDir.java b/Launcher/source/hasher/HashedDir.java index de81114..f54bdb4 100644 --- a/Launcher/source/hasher/HashedDir.java +++ b/Launcher/source/hasher/HashedDir.java @@ -14,6 +14,7 @@ import launcher.LauncherAPI; import launcher.helper.IOHelper; +import launcher.helper.VerifyHelper; import launcher.serialize.HInput; import launcher.serialize.HOutput; import launcher.serialize.stream.EnumSerializer; @@ -35,9 +36,6 @@ int entriesCount = input.readLength(0); for (int i = 0; i < entriesCount; i++) { String name = IOHelper.verifyFileName(input.readString(255)); - if (map.containsKey(name)) { - throw new IOException(String.format("Duplicate hashed entry: '%s'", name)); - } // Read entry HashedEntry entry; @@ -54,9 +52,7 @@ } // Try add entry to map - if (map.put(name, entry) != null) { - throw new IOException(String.format("Duplicate dir entry: '%s'", name)); - } + VerifyHelper.putIfAbsent(map, name, entry, String.format("Duplicate dir entry: '%s'", name)); } } diff --git a/Launcher/source/helper/IOHelper.java b/Launcher/source/helper/IOHelper.java index 8dbb3d5..6c16ea7 100644 --- a/Launcher/source/helper/IOHelper.java +++ b/Launcher/source/helper/IOHelper.java @@ -470,7 +470,7 @@ try { return path.toUri().toURL(); } catch (MalformedURLException e) { - throw new AssertionError(e); + throw new InternalError(e); } } diff --git a/Launcher/source/helper/JVMHelper.java b/Launcher/source/helper/JVMHelper.java index 617834a..ea94e50 100644 --- a/Launcher/source/helper/JVMHelper.java +++ b/Launcher/source/helper/JVMHelper.java @@ -170,7 +170,7 @@ if (name.startsWith("Mac OS X")) { return MACOSX; } - throw new IllegalArgumentException(String.format("This shit is not yet supported: '%s'", name)); + throw new RuntimeException(String.format("This shit is not yet supported: '%s'", name)); } } } diff --git a/Launcher/source/request/update/UpdateRequest.java b/Launcher/source/request/update/UpdateRequest.java index e685a0b..e99a64a 100644 --- a/Launcher/source/request/update/UpdateRequest.java +++ b/Launcher/source/request/update/UpdateRequest.java @@ -196,7 +196,7 @@ // Verify digest byte[] digestBytes = digest.digest(); if (!hFile.isSameDigest(digestBytes)) { - throw new IOException(String.format("File digest mismatch: '%s'", filePath)); + throw new SecurityException(String.format("File digest mismatch: '%s'", filePath)); } } diff --git a/Launcher/source/serialize/config/entry/BlockConfigEntry.java b/Launcher/source/serialize/config/entry/BlockConfigEntry.java index dfe8192..5fae5e4 100644 --- a/Launcher/source/serialize/config/entry/BlockConfigEntry.java +++ b/Launcher/source/serialize/config/entry/BlockConfigEntry.java @@ -101,9 +101,7 @@ ConfigEntry entry = readEntry(input, ro); // Try add entry to map - if (map.put(name, entry) != null) { - throw new IOException(String.format("Duplicate config entry: '%s'", name)); - } + VerifyHelper.putIfAbsent(map, name, entry, String.format("Duplicate config entry: '%s'", name)); } return map; } diff --git a/Launcher/source/serialize/config/entry/ConfigEntry.java b/Launcher/source/serialize/config/entry/ConfigEntry.java index f550ec1..0c4e7ea 100644 --- a/Launcher/source/serialize/config/entry/ConfigEntry.java +++ b/Launcher/source/serialize/config/entry/ConfigEntry.java @@ -73,7 +73,7 @@ case BLOCK: return new BlockConfigEntry(input, ro); default: - throw new IOException("Unsupported config entry type: " + type.name()); + throw new AssertionError("Unsupported config entry type: " + type.name()); } } diff --git a/Launcher/source/serialize/stream/EnumSerializer.java b/Launcher/source/serialize/stream/EnumSerializer.java index 91f083c..a8fef48 100644 --- a/Launcher/source/serialize/stream/EnumSerializer.java +++ b/Launcher/source/serialize/stream/EnumSerializer.java @@ -6,6 +6,7 @@ import java.util.Map; import launcher.LauncherAPI; +import launcher.helper.VerifyHelper; import launcher.serialize.HInput; import launcher.serialize.HOutput; import launcher.serialize.stream.EnumSerializer.Itf; @@ -25,7 +26,7 @@ try { itf = (Itf) field.get(null); } catch (IllegalAccessException e) { - throw new RuntimeException(e); + throw new InternalError(e); } map.put(itf.getNumber(), clazz.cast(itf)); } @@ -34,11 +35,7 @@ @LauncherAPI public E read(HInput input) throws IOException { int n = input.readVarInt(); - E e = map.get(n); - if (e == null) { - throw new IOException("Unknown enum number: " + n); - } - return e; + return VerifyHelper.getMapValue(map, n, "Unknown enum number: " + n); } @LauncherAPI