Reduce exception guard 82/101382/7
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 31 May 2022 19:04:53 +0000 (21:04 +0200)
committerRobert Varga <nite@hq.sk>
Thu, 28 Jul 2022 23:39:07 +0000 (23:39 +0000)
We really should not be catching Exceptions here and once connect()
returns we should be completely asynchronous. Reduce the amount of
code protected by the try/catch block.

Change-Id: I673cc4f0a52cefd2659a5db5a96417e00fd89422
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionPromise.java

index 178be8bfe1f3ef13ec748eb6c2c39aad2af929f7..4a8fb7f88c897b885eff082010e7b55898a165a6 100644 (file)
@@ -54,18 +54,21 @@ final class NetconfSessionPromise<S extends NetconfSession> extends DefaultPromi
 
         LOG.debug("Promise {} attempting connect for {}ms", this, timeout);
 
+        final ChannelFuture connectFuture;
         try {
             if (address.isUnresolved()) {
                 address = new InetSocketAddress(address.getHostName(), address.getPort());
             }
-            final ChannelFuture connectFuture = bootstrap.connect(address);
-            pending = connectFuture;
-            // Add listener that attempts reconnect by invoking this method again.
-            connectFuture.addListener((ChannelFutureListener) this::channelConnectComplete);
+            connectFuture = bootstrap.connect(address);
         } catch (final Exception e) {
             LOG.info("Failed to connect to {}", address, e);
             setFailure(e);
+            return;
         }
+
+        pending = connectFuture;
+        // Add listener that attempts reconnect by invoking this method again.
+        connectFuture.addListener((ChannelFutureListener) this::channelConnectComplete);
     }
 
     @Override