Add try-finally block to ensure removal of FCP listener.
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Wed, 18 Mar 2009 23:46:05 +0000 (00:46 +0100)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 19 Mar 2009 22:09:10 +0000 (23:09 +0100)
src/net/pterodactylus/fcp/highlevel/FcpClient.java

index bcf529b..21dc647 100644 (file)
@@ -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();
                }