Remove use of Objects.isNull/nonNull 75/82575/4
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 20 Jun 2019 09:16:33 +0000 (11:16 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 20 Jun 2019 09:50:45 +0000 (11:50 +0200)
These methods obscure null checks from static analysis tools,
and are explicitly documented to be intended for method references
only -- remove them in favor of proper null checks.

Change-Id: Ibe0a20015eb55d92f19b0ac487a8e48a186216a3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/TesttoolParameters.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/VirtualKeyPairProvider.java

index 2593a98bd726fbb16e21515f6d5164ca85e7aa93..8d32fb3014f1f62f26aaa735a048dd3a789f4ee2 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.netconf.topology.singleton.impl;
 
 import static com.google.common.base.Preconditions.checkState;
-import static java.util.Objects.isNull;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.VisibleForTesting;
@@ -217,10 +216,9 @@ public class RemoteDeviceConnectorImpl implements RemoteDeviceConnector {
         NetconfDeviceCommunicator netconfDeviceCommunicator =
              userCapabilities.isPresent() ? new NetconfDeviceCommunicator(remoteDeviceId, device,
              new UserPreferences(userCapabilities.get(),
-                 isNull(node.getYangModuleCapabilities())
-                         ? false : node.getYangModuleCapabilities().isOverride(),
-                 isNull(node.getNonModuleCapabilities())
-                         ? false : node.getNonModuleCapabilities().isOverride()), rpcMessageLimit)
+                 node.getYangModuleCapabilities() == null ? false : node.getYangModuleCapabilities().isOverride(),
+                 node.getNonModuleCapabilities() == null ? false : node.getNonModuleCapabilities().isOverride()),
+             rpcMessageLimit)
             : new NetconfDeviceCommunicator(remoteDeviceId, device, rpcMessageLimit);
 
         if (salFacade instanceof KeepaliveSalFacade) {
index 3ba5fece8d1621aeede7933e27cd62566c095566..b8cea1bdd49bc0aa4f3d5f13b19544291e1888f9 100644 (file)
@@ -5,7 +5,6 @@
  * 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.netconf.test.tool;
 
 import static com.google.common.base.Preconditions.checkArgument;
@@ -27,7 +26,6 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Objects;
 import java.util.StringJoiner;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Matcher;
@@ -314,10 +312,10 @@ public class TesttoolParameters {
                 if (!matcher.matches()) {
                     try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
                         String line = reader.readLine();
-                        while (Objects.nonNull(line) && !REVISION_DATE_PATTERN.matcher(line).find()) {
+                        while (line != null && !REVISION_DATE_PATTERN.matcher(line).find()) {
                             line = reader.readLine();
                         }
-                        if (Objects.nonNull(line)) {
+                        if (line != null) {
                             final Matcher m = REVISION_DATE_PATTERN.matcher(line);
                             Preconditions.checkState(m.find());
                             String moduleName = file.getAbsolutePath();
index 4d389f73b77e97ce447e24afa41aa06546d3fccb..1b0aab98d7b20a1804303d321a07ee8d02fcc4d9 100644 (file)
@@ -5,7 +5,6 @@
  * 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.netconf.test.tool;
 
 import java.security.GeneralSecurityException;
@@ -13,7 +12,6 @@ import java.security.KeyPair;
 import java.security.KeyPairGenerator;
 import java.security.spec.AlgorithmParameterSpec;
 import java.util.Collections;
-import java.util.Objects;
 import org.apache.sshd.common.cipher.ECCurves;
 import org.apache.sshd.common.config.keys.KeyUtils;
 import org.apache.sshd.common.keyprovider.KeyPairProvider;
@@ -27,7 +25,6 @@ import org.slf4j.LoggerFactory;
  * If the key-pair has already been generated, the existing one is used.
  */
 public class VirtualKeyPairProvider implements KeyPairProvider {
-
     private static final Logger LOG = LoggerFactory.getLogger(VirtualKeyPairProvider.class);
 
     private KeyPair generatedKeyPair;
@@ -52,7 +49,7 @@ public class VirtualKeyPairProvider implements KeyPairProvider {
      * @param keySpecification Algorithm-specific settings.
      * @param keySize          To be generated key length (must be adjusted against selected algorithm).
      */
-    @SuppressWarnings({"unused", "WeakerAccess"})
+    @SuppressWarnings("WeakerAccess")
     VirtualKeyPairProvider(final String algorithm,
                            final AlgorithmParameterSpec keySpecification,
                            final Integer keySize) {
@@ -63,13 +60,13 @@ public class VirtualKeyPairProvider implements KeyPairProvider {
 
     @Override
     public synchronized Iterable<KeyPair> loadKeys(final SessionContext session) {
-        if (Objects.isNull(generatedKeyPair)) {
+        if (generatedKeyPair == null) {
             try {
                 generatedKeyPair = generateKeyPair();
-            } catch (GeneralSecurityException exception) {
+            } catch (GeneralSecurityException e) {
                 LOG.error("Cannot generate key with algorithm '{}', key specification '{}', and key size '{}'.",
-                        algorithm, keySpecification, keySize, exception);
-                throw new IllegalArgumentException("An error occurred during generation of a new ke pair.", exception);
+                        algorithm, keySpecification, keySize, e);
+                throw new IllegalArgumentException("An error occurred during generation of a new ke pair.", e);
             }
         }
         return Collections.singleton(generatedKeyPair);
@@ -83,9 +80,9 @@ public class VirtualKeyPairProvider implements KeyPairProvider {
      */
     private KeyPair generateKeyPair() throws GeneralSecurityException {
         final KeyPairGenerator generator = SecurityUtils.getKeyPairGenerator(algorithm);
-        if (Objects.nonNull(keySpecification)) {
+        if (keySpecification != null) {
             generator.initialize(keySpecification);
-        } else if (Objects.nonNull(keySize)) {
+        } else if (keySize != null) {
             generator.initialize(keySize);
         } else if (KeyUtils.EC_ALGORITHM.equals(algorithm)) {
             int numCurves = ECCurves.SORTED_KEY_SIZE.size();