Simplify AaaCertProvider.getCipherSuites() 56/104256/2
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 5 Feb 2023 16:58:04 +0000 (17:58 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 6 Feb 2023 09:20:27 +0000 (10:20 +0100)
The API spec says we are allowed to return empty array, do that in a
very straightforward manner, eliminating a @SuppressFBWarnings.

Change-Id: Iab3b32df81772611233d77b462ba0ed4a0f30621
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
aaa-cert/src/main/java/org/opendaylight/aaa/cert/impl/AaaCertProvider.java

index c532f83c24d9707d02c2584549b8ebff8b49b680..ec21ff63e474d7dd637ffd30cec773608daded67 100644 (file)
@@ -5,13 +5,10 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.aaa.cert.impl;
 
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.security.KeyStore;
-import java.util.ArrayList;
-import java.util.List;
 import org.opendaylight.aaa.cert.api.IAaaCertProvider;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.yang.aaa.cert.rev151126.aaa.cert.service.config.CtlKeystore;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.yang.aaa.cert.rev151126.aaa.cert.service.config.TrustKeystore;
@@ -139,19 +136,11 @@ public class AaaCertProvider implements IAaaCertProvider {
     }
 
     @Override
-    @SuppressFBWarnings("PZLA_PREFER_ZERO_LENGTH_ARRAYS")
     public String[] getCipherSuites() {
-        final List<CipherSuites> cipherSuites = ctlKeyStore.getCipherSuites();
-        if (cipherSuites != null && !cipherSuites.isEmpty()) {
-            final List<String> suites = new ArrayList<>();
-            cipherSuites.stream().forEach(cs -> {
-                if (!cs.getSuiteName().isEmpty()) {
-                    suites.add(cs.getSuiteName());
-                }
-            });
-            return suites.toArray(new String[suites.size()]);
-        }
-        return null;
+        return ctlKeyStore.nonnullCipherSuites().stream()
+            .map(CipherSuites::getSuiteName)
+            .filter(name -> !name.isEmpty())
+            .toArray(String[]::new);
     }
 
     @Override