From a9aa26d372a3c018132351153b308e053bafc9d4 Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Tue, 25 Oct 2016 01:12:12 -0400 Subject: [PATCH 1/1] Fix FindBugs warnings in cds-access-client and enable enforcement Change-Id: I295538aa4af61c1eec81fd5b9143c5514bf17f2e Signed-off-by: Tom Pantelis --- opendaylight/md-sal/cds-access-client/pom.xml | 7 +++++++ .../cluster/access/client/SequencedQueue.java | 13 +++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/opendaylight/md-sal/cds-access-client/pom.xml b/opendaylight/md-sal/cds-access-client/pom.xml index 376be8c107..e229b4114a 100644 --- a/opendaylight/md-sal/cds-access-client/pom.xml +++ b/opendaylight/md-sal/cds-access-client/pom.xml @@ -81,6 +81,13 @@ checkstyle.violationSeverity=error + + org.codehaus.mojo + findbugs-maven-plugin + + true + + diff --git a/opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/SequencedQueue.java b/opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/SequencedQueue.java index 0e8d1b9d56..596e353c98 100644 --- a/opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/SequencedQueue.java +++ b/opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/SequencedQueue.java @@ -11,6 +11,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.base.Ticker; import com.google.common.base.Verify; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.ArrayDeque; import java.util.Iterator; import java.util.Optional; @@ -154,8 +155,14 @@ final class SequencedQueue { } // Ready to transmit - currentInflight.offer(e); - LOG.debug("Enqueued request {} to queue {}", request, this); + + if (currentInflight.offer(e)) { + LOG.debug("Enqueued request {} to queue {}", request, this); + } else { + // This shouldn't happen since the queue has unlimited capacity but check anyway to avoid FindBugs warning + // about checking return value. + LOG.warn("Fail to enqueued request {} to queue {}", request, this); + } e.retransmit(backend, nextTxSequence(), now); if (expectingTimer == null) { @@ -172,6 +179,8 @@ final class SequencedQueue { * - if a matching entry is not found, but it makes sense to keep looking at other queues, return null * - if a conflicting entry is encountered, indicating we should ignore this request, return an empty Optional */ + @SuppressFBWarnings(value = "NP_OPTIONAL_RETURN_NULL", + justification = "Returning null Optional is documented in the API contract.") private static Optional findMatchingEntry(final Queue queue, final ResponseEnvelope envelope) { // Try to find the request in a queue. Responses may legally come back in a different order, hence we need -- 2.36.6