Cleanup switch certificate chain handling
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / connection / listener / SystemNotificationsListenerImpl.java
index 5bbfc273b449a927d378c7a7002cba4d16742ba9..2c1798d983c7984e7f4197d92290a08de68932e6 100644 (file)
@@ -142,23 +142,24 @@ public class SystemNotificationsListenerImpl implements SystemNotificationsListe
 
     @Override
     public void onSslConnectionError(final SslConnectionError notification) {
-        IpAddress ip = null;
+        final IpAddress ip;
         if (connectionContext.getConnectionAdapter() != null
                 && connectionContext.getConnectionAdapter().getRemoteAddress() != null
                 && connectionContext.getConnectionAdapter().getRemoteAddress().getAddress() != null) {
             ip = IpAddressBuilder.getDefaultInstance(
                     connectionContext.getConnectionAdapter().getRemoteAddress().getAddress().getHostAddress());
+        } else {
+            ip = null;
         }
-        SwitchCertificateBuilder switchCertificateBuilder = new SwitchCertificateBuilder();
-        if (notification.getSwitchCertificate() != null) {
-            switchCertificateBuilder = new SwitchCertificateBuilder(notification.getSwitchCertificate());
-        }
+
+        final var switchCert = notification.getSwitchCertificate();
+
         notificationPublishService.offerNotification(new SslErrorBuilder()
             .setType(SslErrorType.SslConFailed)
             .setCode(Uint16.valueOf(SslErrorType.SslConFailed.getIntValue()))
             .setNodeIpAddress(ip)
             .setData(notification.getInfo())
-            .setSwitchCertificate(notification.getSwitchCertificate() != null ? switchCertificateBuilder.build() : null)
+            .setSwitchCertificate(switchCert == null ? null : new SwitchCertificateBuilder(switchCert).build())
             .build());
     }
 }