Avoid returning null Optional 61/61161/1
authorStephen Kitt <skitt@redhat.com>
Fri, 4 Aug 2017 10:50:38 +0000 (12:50 +0200)
committerStephen Kitt <skitt@redhat.com>
Fri, 4 Aug 2017 10:50:38 +0000 (12:50 +0200)
Optional references should never be null, this patch uses
Optional.absent() instead and cleans up the caller.

Change-Id: Iac1888abf60785a3d3f0f1493bbd71751dd0fbc9
Signed-off-by: Stephen Kitt <skitt@redhat.com>
netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallhomeStatusReporter.java

index ee068ec1fb20e37cc1d40062e696113463f356ac..da3996e0e7639dfe762103e81d69b885d5d4bdf9 100644 (file)
@@ -18,6 +18,7 @@ import java.security.spec.InvalidKeySpecException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
@@ -198,16 +199,10 @@ class CallhomeStatusReporter implements DataChangeListener, StatusRecorder, Auto
     }
 
     private Device readAndGetDevice(NodeId nodeId) {
-        Optional<Device> opDevGet = readDevice(nodeId);
-        if (opDevGet != null) {
-            if (opDevGet.isPresent()) {
-                return opDevGet.get();
-            }
-        }
-
-        return null;
+        return readDevice(nodeId).orNull();
     }
 
+    @Nonnull
     private Optional<Device> readDevice(NodeId nodeId) {
         ReadOnlyTransaction opTx = dataBroker.newReadOnlyTransaction();
 
@@ -218,7 +213,7 @@ class CallhomeStatusReporter implements DataChangeListener, StatusRecorder, Auto
         try {
             return devFuture.checkedGet();
         } catch (ReadFailedException e) {
-            return null;
+            return Optional.absent();
         }
     }