From 7ba231850692a5492dce5f5537543a400f1e330c Mon Sep 17 00:00:00 2001 From: A248 Date: Fri, 2 Apr 2021 01:45:58 -0400 Subject: [PATCH] Fix one more case of a possibly swallowed exception (#455) Maybe spotbugs will add a rule for this in the future --- .../connection/client/LoginSessionHandler.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java index 230d50d56..c1967e858 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java @@ -309,7 +309,11 @@ public class LoginSessionHandler implements MinecraftSessionHandler { mcConnection.setSessionHandler(new InitialConnectSessionHandler(player)); server.getEventManager().fire(new PostLoginEvent(player)) - .thenRun(() -> connectToInitialServer(player)); + .thenCompose((ignored) -> connectToInitialServer(player)) + .exceptionally((ex) -> { + logger.error("Exception while connecting {} to initial server", player, ex); + return null; + }); } }, mcConnection.eventLoop()) .exceptionally((ex) -> { @@ -318,12 +322,12 @@ public class LoginSessionHandler implements MinecraftSessionHandler { }); } - private void connectToInitialServer(ConnectedPlayer player) { + private CompletableFuture connectToInitialServer(ConnectedPlayer player) { Optional initialFromConfig = player.getNextServerToTry(); PlayerChooseInitialServerEvent event = new PlayerChooseInitialServerEvent(player, initialFromConfig.orElse(null)); - server.getEventManager().fire(event) + return server.getEventManager().fire(event) .thenRunAsync(() -> { Optional toTry = event.getInitialServer(); if (!toTry.isPresent()) { @@ -332,11 +336,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { return; } player.createConnectionRequest(toTry.get()).fireAndForget(); - }, mcConnection.eventLoop()) - .exceptionally((ex) -> { - logger.error("Exception while connecting {} to initial server", player, ex); - return null; - }); + }, mcConnection.eventLoop()); } @Override