Fix findbugs violations in netconf
[netconf.git] / netconf / netconf-client / src / main / java / org / opendaylight / netconf / client / TcpClientChannelInitializer.java
index 84f4bf9f3238c54a91f75cb500ce0c1f79756222..5f25800b4b0c595137485c78fc0bc095c1114e82 100644 (file)
@@ -41,23 +41,24 @@ class TcpClientChannelInitializer extends AbstractChannelInitializer<NetconfClie
             GenericFutureListener<Future<NetconfClientSession>> negotiationFutureListener;
 
             @Override
-            public void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress, final SocketAddress localAddress,
+            public void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress,
+                                final SocketAddress localAddress,
                                 final ChannelPromise channelPromise) throws Exception {
                 connectPromise = channelPromise;
                 ChannelPromise tcpConnectFuture = new DefaultChannelPromise(ch);
 
                 negotiationFutureListener = future -> {
                     if (future.isSuccess()) {
-                        connectPromise.setSuccess();
+                        channelPromise.setSuccess();
                     }
                 };
 
                 tcpConnectFuture.addListener(future -> {
-                    if(future.isSuccess()) {
+                    if (future.isSuccess()) {
                         //complete connection promise with netconf negotiation future
                         negotiationFuture.addListener(negotiationFutureListener);
                     } else {
-                        connectPromise.setFailure(future.cause());
+                        channelPromise.setFailure(future.cause());
                     }
                 });
                 ctx.connect(remoteAddress, localAddress, tcpConnectFuture);
@@ -65,14 +66,19 @@ class TcpClientChannelInitializer extends AbstractChannelInitializer<NetconfClie
 
             @Override
             public void disconnect(final ChannelHandlerContext ctx, final ChannelPromise promise) throws Exception {
-                // If we have already succeeded and the session was dropped after, we need to fire inactive to notify reconnect logic
-                if(connectPromise.isSuccess()) {
+                if (connectPromise == null) {
+                    return;
+                }
+
+                // If we have already succeeded and the session was dropped after, we need to fire inactive to notify
+                // reconnect logic
+                if (connectPromise.isSuccess()) {
                     ctx.fireChannelInactive();
                 }
 
                 //If connection promise is not already set, it means negotiation failed
                 //we must set connection promise to failure
-                if(!connectPromise.isDone()) {
+                if (!connectPromise.isDone()) {
                     connectPromise.setFailure(new IllegalStateException("Negotiation failed"));
                 }