From 84da1f5f1d0169235d1c71991f62af5e08c7263f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 19 Mar 2009 00:46:05 +0100 Subject: [PATCH] Add try-finally block to ensure removal of FCP listener. --- src/net/pterodactylus/fcp/highlevel/FcpClient.java | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/net/pterodactylus/fcp/highlevel/FcpClient.java b/src/net/pterodactylus/fcp/highlevel/FcpClient.java index bcf529b..21dc647 100644 --- a/src/net/pterodactylus/fcp/highlevel/FcpClient.java +++ b/src/net/pterodactylus/fcp/highlevel/FcpClient.java @@ -142,18 +142,21 @@ public class FcpClient { } }; fcpConnection.addFcpListener(fcpListener); - fcpConnection.connect(); - ClientHello clientHello = new ClientHello(name); - fcpConnection.sendMessage(clientHello); - while (true) { - try { - fcpListener.complete(); - break; - } catch (InterruptedException e) { - /* ignore, we’ll loop. */ + try { + fcpConnection.connect(); + ClientHello clientHello = new ClientHello(name); + fcpConnection.sendMessage(clientHello); + while (true) { + try { + fcpListener.complete(); + break; + } catch (InterruptedException e) { + /* ignore, we’ll loop. */ + } } + } finally { + fcpConnection.removeFcpListener(fcpListener); } - fcpConnection.removeFcpListener(fcpListener); if (fcpListener.getFcpException() != null) { throw fcpListener.getFcpException(); } -- 2.7.4