From e490a2c4a2907a8befa0707741ee1eb7cafac6cd Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 20 Jun 2019 11:16:33 +0200 Subject: [PATCH] Remove use of Objects.isNull/nonNull 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 --- .../impl/RemoteDeviceConnectorImpl.java | 8 +++----- .../netconf/test/tool/TesttoolParameters.java | 6 ++---- .../test/tool/VirtualKeyPairProvider.java | 17 +++++++---------- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java index 2593a98bd7..8d32fb3014 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java @@ -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) { diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/TesttoolParameters.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/TesttoolParameters.java index 3ba5fece8d..b8cea1bdd4 100644 --- a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/TesttoolParameters.java +++ b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/TesttoolParameters.java @@ -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(); diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/VirtualKeyPairProvider.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/VirtualKeyPairProvider.java index 4d389f73b7..1b0aab98d7 100644 --- a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/VirtualKeyPairProvider.java +++ b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/VirtualKeyPairProvider.java @@ -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 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(); -- 2.36.6