Do not use Optional for SslHandler 69/102669/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 12 Oct 2022 09:50:31 +0000 (11:50 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 13 Oct 2022 14:28:09 +0000 (16:28 +0200)
Use a simple @Nullable return instead wrapping and unwrapping it again.

Change-Id: I97d3475d4a8090ca7ac75e67c56d37997a58b859
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 3d5a570ce63aea1383a34512473883fea70ed03d)
(cherry picked from commit 946277d21829da45ff7e2f806ad0919dba59e833)

netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSessionNegotiator.java

index 63c6668a1a9637261e9a707e2df9ff50606f56b4..9c713f1b5c3c5f50feaa542b9a06b3d57b390f0d 100644 (file)
@@ -21,9 +21,9 @@ import io.netty.util.Timeout;
 import io.netty.util.Timer;
 import io.netty.util.concurrent.GenericFutureListener;
 import io.netty.util.concurrent.Promise;
-import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 import org.checkerframework.checker.lock.qual.GuardedBy;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.netconf.api.NetconfDocumentedException;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.NetconfSessionListener;
@@ -83,9 +83,9 @@ public abstract class AbstractNetconfSessionNegotiator<P extends NetconfSessionP
         if (ifNegotiatedAlready()) {
             LOG.debug("Negotiation on channel {} already started", channel);
         } else {
-            final Optional<SslHandler> sslHandler = getSslHandler(channel);
-            if (sslHandler.isPresent()) {
-                sslHandler.get().handshakeFuture().addListener(future -> {
+            final var sslHandler = getSslHandler(channel);
+            if (sslHandler != null) {
+                sslHandler.handshakeFuture().addListener(future -> {
                     checkState(future.isSuccess(), "Ssl handshake was not successful");
                     LOG.debug("Ssl handshake complete");
                     start();
@@ -101,8 +101,8 @@ public abstract class AbstractNetconfSessionNegotiator<P extends NetconfSessionP
         return this.state != State.IDLE;
     }
 
-    private static Optional<SslHandler> getSslHandler(final Channel channel) {
-        return Optional.ofNullable(channel.pipeline().get(SslHandler.class));
+    private static @Nullable SslHandler getSslHandler(final Channel channel) {
+        return channel.pipeline().get(SslHandler.class);
     }
 
     public P getSessionPreferences() {