From dc57b280f7f5baf23dc4564574547616b3a50224 Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Fri, 4 Aug 2017 12:50:38 +0200 Subject: [PATCH] Avoid returning null Optional 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 --- .../callhome/mount/CallhomeStatusReporter.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallhomeStatusReporter.java b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallhomeStatusReporter.java index ee068ec1fb..da3996e0e7 100644 --- a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallhomeStatusReporter.java +++ b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallhomeStatusReporter.java @@ -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 opDevGet = readDevice(nodeId); - if (opDevGet != null) { - if (opDevGet.isPresent()) { - return opDevGet.get(); - } - } - - return null; + return readDevice(nodeId).orNull(); } + @Nonnull private Optional 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(); } } -- 2.36.6