Enable mdsal-dom-broker spotbugs 97/76897/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 11 Oct 2018 16:42:48 +0000 (18:42 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 11 Oct 2018 17:46:30 +0000 (19:46 +0200)
This fixes up the issues reported and flips enforcement to on.

Change-Id: Iae6de422f027e6413b4e3021d4324b051f41a513
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
dom/mdsal-dom-broker/pom.xml
dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/AbstractDOMDataBroker.java
dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/CommitCoordinationTask.java
dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/DOMNotificationRouter.java
dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/DOMRpcRouter.java
dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/ShardedDOMDataTree.java
dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/ShardedDOMWriteTransactionAdapter.java
dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/UnknownDOMRpcRoutingTableEntry.java

index 2ef75c0ad496c3396551361b45edd21852f1f410..15b61d90c0a4cff9e03506606767c83116c18c9f 100644 (file)
                     <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>com.github.spotbugs</groupId>
+                <artifactId>spotbugs-maven-plugin</artifactId>
+                <configuration>
+                    <failOnError>true</failOnError>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
     <scm>
index 95ffcfc5a7dba6b9be1fe5e081da1569f10fb1f2..e0b571f1e6a17e7e254a00e9e9da9f2bda756564 100644 (file)
@@ -30,7 +30,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public abstract class AbstractDOMDataBroker extends AbstractDOMForwardedTransactionFactory<DOMStore>
-        implements DOMDataBroker, AutoCloseable {
+        implements DOMDataBroker {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractDOMDataBroker.class);
 
     private final AtomicLong txNum = new AtomicLong();
index d243a4da1ec48506c53d2d6861e649a1677bfa52..262b0b35dd9175fe02676a78f3b2db72aab721c6 100644 (file)
@@ -5,13 +5,13 @@
  * 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.mdsal.dom.broker;
 
 import com.google.common.base.Preconditions;
 import com.google.common.base.Throwables;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.Collection;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
@@ -24,8 +24,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Implementation of blocking three-phase commit-coordination tasks without
- * support of cancellation.
+ * Implementation of blocking three-phase commit-coordination tasks without support of cancellation.
  */
 final class CommitCoordinationTask implements Callable<CommitInfo> {
     private enum Phase {
@@ -79,17 +78,15 @@ final class CommitCoordinationTask implements Callable<CommitInfo> {
     }
 
     /**
-     * Invokes canCommit on underlying cohorts and blocks till
-     * all results are returned.
-     *
-     *<p>
-     * Valid state transition is from SUBMITTED to CAN_COMMIT,
-     * if currentPhase is not SUBMITTED throws IllegalStateException.
+     * Invokes canCommit on underlying cohorts and blocks till all results are returned.
      *
-     * @throws TransactionCommitFailedException
-     *             If one of cohorts failed can Commit
+     * <p>
+     * Valid state transition is from SUBMITTED to CAN_COMMIT, if currentPhase is not SUBMITTED throws
+     * IllegalStateException.
      *
+     * @throws TransactionCommitFailedException If one of cohorts failed can Commit
      */
+    @SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
     private void canCommitBlocking() throws TransactionCommitFailedException {
         for (final ListenableFuture<?> canCommit : canCommitAll()) {
             try {
@@ -104,16 +101,14 @@ final class CommitCoordinationTask implements Callable<CommitInfo> {
     }
 
     /**
-     * Invokes canCommit on underlying cohorts and returns composite future
-     * which will contains {@link Boolean#TRUE} only and only if
-     * all cohorts returned true.
+     * Invokes canCommit on underlying cohorts and returns composite future which will contain {@link Boolean#TRUE} only
+     * and only if all cohorts returned true.
      *
-     *<p>
-     * Valid state transition is from SUBMITTED to CAN_COMMIT,
-     * if currentPhase is not SUBMITTED throws IllegalStateException.
+     * <p>
+     * Valid state transition is from SUBMITTED to CAN_COMMIT, if currentPhase is not SUBMITTED throws
+     * IllegalStateException.
      *
      * @return List of all cohorts futures from can commit phase.
-     *
      */
     private ListenableFuture<?>[] canCommitAll() {
         final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
@@ -125,18 +120,15 @@ final class CommitCoordinationTask implements Callable<CommitInfo> {
     }
 
     /**
-     * Invokes preCommit on underlying cohorts and blocks till
-     * all results are returned.
+     * Invokes preCommit on underlying cohorts and blocks until all results are returned.
      *
-     *<p>
-     * Valid state transition is from CAN_COMMIT to PRE_COMMIT, if current
-     * state is not CAN_COMMIT
-     * throws IllegalStateException.
-     *
-     * @throws TransactionCommitFailedException
-     *             If one of cohorts failed preCommit
+     * <p>
+     * Valid state transition is from CAN_COMMIT to PRE_COMMIT, if current state is not CAN_COMMIT throws
+     * IllegalStateException.
      *
+     * @throws TransactionCommitFailedException If one of cohorts failed preCommit
      */
+    @SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
     private void preCommitBlocking() throws TransactionCommitFailedException {
         final ListenableFuture<?>[] preCommitFutures = preCommitAll();
         try {
@@ -149,17 +141,14 @@ final class CommitCoordinationTask implements Callable<CommitInfo> {
     }
 
     /**
-     * Invokes preCommit on underlying cohorts and returns future
-     * which will complete once all preCommit on cohorts completed or
-     * failed.
+     * Invokes preCommit on underlying cohorts and returns future which will complete once all preCommit on cohorts
+     * completed or failed.
      *
-     *<p>
-     * Valid state transition is from CAN_COMMIT to PRE_COMMIT, if current
-     * state is not CAN_COMMIT
-     * throws IllegalStateException.
+     * <p>
+     * Valid state transition is from CAN_COMMIT to PRE_COMMIT, if current state is not CAN_COMMIT throws
+     * IllegalStateException.
      *
      * @return List of all cohorts futures from can commit phase.
-     *
      */
     private ListenableFuture<?>[] preCommitAll() {
         final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
@@ -171,17 +160,14 @@ final class CommitCoordinationTask implements Callable<CommitInfo> {
     }
 
     /**
-     * Invokes commit on underlying cohorts and blocks till
-     * all results are returned.
+     * Invokes commit on underlying cohorts and blocks until all results are returned.
      *
-     *<p>
-     * Valid state transition is from PRE_COMMIT to COMMIT, if not throws
-     * IllegalStateException.
-     *
-     * @throws TransactionCommitFailedException
-     *             If one of cohorts failed preCommit
+     * <p>
+     * Valid state transition is from PRE_COMMIT to COMMIT, if not throws IllegalStateException.
      *
+     * @throws TransactionCommitFailedException If one of cohorts failed preCommit
      */
+    @SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
     private void commitBlocking() throws TransactionCommitFailedException {
         final ListenableFuture<?>[] commitFutures = commitAll();
         try {
@@ -216,26 +202,18 @@ final class CommitCoordinationTask implements Callable<CommitInfo> {
     /**
      * Aborts transaction.
      *
-     *<p>
-     * Invokes {@link DOMStoreThreePhaseCommitCohort#abort()} on all
-     * cohorts, blocks
-     * for all results. If any of the abort failed throws
-     * IllegalStateException,
-     * which will contains originalCause as suppressed Exception.
+     * <p>
+     * Invokes {@link DOMStoreThreePhaseCommitCohort#abort()} on all cohorts, blocks for all results. If any
+     * of the abort failed throws IllegalStateException, which will contains originalCause as suppressed Exception.
      *
-     *<p>
+     * <p>
      * If aborts we're successful throws supplied exception
      *
-     * @param originalCause
-     *            Exception which should be used to fail transaction for
-     *            consumers of transaction
-     *            future and listeners of transaction failure.
+     * @param originalCause Exception which should be used to fail transaction for consumers of transaction future
+     *                      and listeners of transaction failure.
      * @param phase phase in which the problem ensued
-     * @throws TransactionCommitFailedException
-     *             on invocation of this method.
-     *             originalCa
-     * @throws IllegalStateException
-     *             if abort failed.
+     * @throws TransactionCommitFailedException on invocation of this method.
+     * @throws IllegalStateException if abort failed.
      */
     private void abortBlocking(final TransactionCommitFailedException originalCause)
             throws TransactionCommitFailedException {
@@ -251,11 +229,9 @@ final class CommitCoordinationTask implements Callable<CommitInfo> {
     }
 
     /**
-     * Invokes abort on underlying cohorts and returns future which
-     * completes once all abort on cohorts are completed.
+     * Invokes abort on underlying cohorts and returns future which completes once all abort on cohorts are completed.
      *
-     * @return Future which will complete once all cohorts completed
-     *         abort.
+     * @return Future which will complete once all cohorts completed abort.
      */
     @SuppressWarnings({"unchecked", "rawtypes"})
     private ListenableFuture<Void> abortAsyncAll() {
index e8a307c95841474ed3afdf7e86cd195a40981475..f84ef6699efd2c3646f6d3a279a475960e94671e 100644 (file)
@@ -45,7 +45,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 /**
  * Joint implementation of {@link DOMNotificationPublishService} and {@link DOMNotificationService}. Provides
  * routing of notifications from publishers to subscribers.
@@ -84,7 +83,6 @@ public class DOMNotificationRouter implements AutoCloseable, DOMNotificationPubl
             ListenerRegistry.create();
     private final ScheduledThreadPoolExecutor observer;
 
-    @SuppressWarnings("unchecked")
     @VisibleForTesting
     DOMNotificationRouter(final ExecutorService executor, final int queueDepth, final WaitStrategy strategy) {
         this.executor = Preconditions.checkNotNull(executor);
@@ -162,7 +160,7 @@ public class DOMNotificationRouter implements AutoCloseable, DOMNotificationPubl
     private void notifyListenerTypesChanged(final Set<SchemaPath> typesAfter) {
         final List<ListenerRegistration<DOMNotificationSubscriptionListener>> listenersAfter =
                 ImmutableList.copyOf(subscriptionListeners.getListeners());
-        executor.submit(() -> {
+        executor.execute(() -> {
             for (final ListenerRegistration<DOMNotificationSubscriptionListener> subListener : listenersAfter) {
                 try {
                     subListener.getInstance().onSubscriptionChanged(typesAfter);
@@ -177,7 +175,7 @@ public class DOMNotificationRouter implements AutoCloseable, DOMNotificationPubl
     public <L extends DOMNotificationSubscriptionListener> ListenerRegistration<L> registerSubscriptionListener(
             final L listener) {
         final Set<SchemaPath> initialTypes = listeners.keySet();
-        executor.submit(() -> listener.onSubscriptionChanged(initialTypes));
+        executor.execute(() -> listener.onSubscriptionChanged(initialTypes));
         return subscriptionListeners.registerWithType(listener);
     }
 
index 317009d71e49e5f38dcf3a2c03d13878a0bc8ff8..f0215481c67ecf575700aa1b7c7d2b6752f9f0d7 100644 (file)
@@ -184,7 +184,7 @@ public final class DOMRpcRouter extends AbstractRegistration implements SchemaCo
     }
 
     @VisibleForTesting
-    Collection<?> listeners() {
+    synchronized Collection<?> listeners() {
         return listeners;
     }
 
index 804beedb6a29a5a31a8f31d7c26fd46d2b36b8c7..71e63d80942bd953d2e907b75450c9e79f870259 100644 (file)
@@ -7,8 +7,10 @@
  */
 package org.opendaylight.mdsal.dom.broker;
 
-import com.google.common.base.Preconditions;
-import com.google.common.base.Verify;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Verify.verifyNotNull;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.ClassToInstanceMap;
 import com.google.common.collect.ImmutableClassToInstanceMap;
@@ -72,12 +74,13 @@ public final class ShardedDOMDataTree implements DOMDataTreeService, DOMDataTree
     public <T extends DOMDataTreeShard> DOMDataTreeShardRegistration<T> registerDataTreeShard(
             final DOMDataTreeIdentifier prefix, final T shard, final DOMDataTreeProducer producer)
                     throws DOMDataTreeShardingConflictException {
+        checkArgument(producer instanceof ShardedDOMDataTreeProducer, "Unsupported producer %s", producer);
+        final ShardedDOMDataTreeProducer prod = (ShardedDOMDataTreeProducer) producer;
 
-        final DOMDataTreeIdentifier firstSubtree = Iterables.getOnlyElement(((
-                ShardedDOMDataTreeProducer) producer).getSubtrees());
-        Preconditions.checkArgument(firstSubtree != null, "Producer that is used to verify namespace claim can"
+        final DOMDataTreeIdentifier firstSubtree = Iterables.getOnlyElement(prod.getSubtrees());
+        checkArgument(firstSubtree != null, "Producer that is used to verify namespace claim can"
                 + " only claim a single namespace");
-        Preconditions.checkArgument(prefix.equals(firstSubtree), "Trying to register shard to a different namespace"
+        checkArgument(prefix.equals(firstSubtree), "Trying to register shard to a different namespace"
                 + " than the producer has claimed");
 
         final DOMDataTreeShardRegistration<T> reg;
@@ -106,7 +109,7 @@ public final class ShardedDOMDataTree implements DOMDataTreeService, DOMDataTree
 
             shards.store(prefix, reg);
 
-            ((ShardedDOMDataTreeProducer) producer).subshardAdded(Collections.singletonMap(prefix, shard));
+            prod.subshardAdded(Collections.singletonMap(prefix, shard));
         }
 
         // Notify the parent shard
@@ -152,13 +155,13 @@ public final class ShardedDOMDataTree implements DOMDataTreeService, DOMDataTree
 
     @Override
     public synchronized DOMDataTreeProducer createProducer(final Collection<DOMDataTreeIdentifier> subtrees) {
-        Preconditions.checkArgument(!subtrees.isEmpty(), "Subtrees may not be empty");
+        checkArgument(!subtrees.isEmpty(), "Subtrees may not be empty");
 
         final Map<DOMDataTreeIdentifier, DOMDataTreeShard> shardMap = new HashMap<>();
         for (final DOMDataTreeIdentifier subtree : subtrees) {
             // Attempting to create a disconnected producer -- all subtrees have to be unclaimed
             final DOMDataTreeProducer producer = findProducer(subtree);
-            Preconditions.checkArgument(producer == null, "Subtree %s is attached to producer %s", subtree, producer);
+            checkArgument(producer == null, "Subtree %s is attached to producer %s", subtree, producer);
 
             final DOMDataTreePrefixTableEntry<DOMDataTreeShardRegistration<?>> possibleShardReg =
                     shards.lookup(subtree);
@@ -172,7 +175,7 @@ public final class ShardedDOMDataTree implements DOMDataTreeService, DOMDataTree
 
     synchronized DOMDataTreeProducer createProducer(final ShardedDOMDataTreeProducer parent,
             final Collection<DOMDataTreeIdentifier> subtrees) {
-        Preconditions.checkNotNull(parent);
+        requireNonNull(parent);
 
         final Map<DOMDataTreeIdentifier, DOMDataTreeShard> shardMap = new HashMap<>();
         for (final DOMDataTreeIdentifier s : subtrees) {
@@ -187,7 +190,7 @@ public final class ShardedDOMDataTree implements DOMDataTreeService, DOMDataTree
     public synchronized <T extends DOMDataTreeListener> ListenerRegistration<T> registerListener(final T listener,
             final Collection<DOMDataTreeIdentifier> subtrees, final boolean allowRxMerges,
             final Collection<DOMDataTreeProducer> producers) throws DOMDataTreeLoopException {
-        Preconditions.checkNotNull(listener, "listener");
+        requireNonNull(listener, "listener");
 
         // Cross-check specified trees for exclusivity and eliminate duplicates, noDupSubtrees is effectively a Set
         final Collection<DOMDataTreeIdentifier> noDupSubtrees;
@@ -202,8 +205,8 @@ public final class ShardedDOMDataTree implements DOMDataTreeService, DOMDataTree
                 for (DOMDataTreeIdentifier toCheck : subtrees) {
                     for (DOMDataTreeIdentifier against : subtrees) {
                         if (!toCheck.equals(against)) {
-                            Preconditions.checkArgument(!toCheck.contains(against), "Subtree %s contains subtree %s",
-                                toCheck, against);
+                            checkArgument(!toCheck.contains(against), "Subtree %s contains subtree %s", toCheck,
+                                against);
                         }
                     }
                 }
@@ -217,7 +220,7 @@ public final class ShardedDOMDataTree implements DOMDataTreeService, DOMDataTree
         final ListMultimap<DOMDataTreeShardRegistration<?>, DOMDataTreeIdentifier> needed =
                 ArrayListMultimap.create();
         for (final DOMDataTreeIdentifier subtree : subtrees) {
-            final DOMDataTreeShardRegistration<?> reg = Verify.verifyNotNull(shards.lookup(subtree).getValue());
+            final DOMDataTreeShardRegistration<?> reg = verifyNotNull(shards.lookup(subtree).getValue());
             needed.put(reg, subtree);
         }
 
@@ -226,14 +229,14 @@ public final class ShardedDOMDataTree implements DOMDataTreeService, DOMDataTree
         // Sanity check: all selected shards have to support one of the listening interfaces
         needed.asMap().forEach((reg, trees) -> {
             final DOMDataTreeShard shard = reg.getInstance();
-            Preconditions.checkArgument(shard instanceof ListenableDOMDataTreeShard
+            checkArgument(shard instanceof ListenableDOMDataTreeShard
                 || shard instanceof DOMStoreTreeChangePublisher, "Subtrees %s do not point to listenable subtree.",
                 trees);
         });
 
         // Sanity check: all producers have to come from this implementation and must not form loops
         for (DOMDataTreeProducer producer : producers) {
-            Preconditions.checkArgument(producer instanceof ShardedDOMDataTreeProducer);
+            checkArgument(producer instanceof ShardedDOMDataTreeProducer);
             simpleLoopCheck(subtrees, ((ShardedDOMDataTreeProducer) producer).getSubtrees());
         }
 
index 594de1565beb7c78d094ca1f64a653ed066be513..063becf8f0781333a98b6becd95b01002828a000 100644 (file)
@@ -101,7 +101,8 @@ public class ShardedDOMWriteTransactionAdapter implements DOMDataTreeWriteTransa
     public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path,
                     final NormalizedNode<?, ?> data) {
         checkRunning();
-        LOG.debug("{}: Invoking put operation at {}:{} with payload {}", txIdentifier, store, path);
+        LOG.debug("{}: Invoking put operation at {}:{}", txIdentifier, store, path);
+        LOG.trace("{}: payload is {}", txIdentifier, data);
         if (!initialized) {
             initializeDataTreeProducerLayer(path.getParent());
         }
@@ -114,7 +115,8 @@ public class ShardedDOMWriteTransactionAdapter implements DOMDataTreeWriteTransa
     public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path,
                       final NormalizedNode<?, ?> data) {
         checkRunning();
-        LOG.debug("{}: Invoking merge operation at {}:{} with payload {}", txIdentifier, store, path);
+        LOG.debug("{}: Invoking merge operation at {}:{}", txIdentifier, store, path);
+        LOG.trace("{}: payload is {}", txIdentifier, data);
         if (!initialized) {
             initializeDataTreeProducerLayer(path.getParent());
         }
@@ -150,7 +152,7 @@ public class ShardedDOMWriteTransactionAdapter implements DOMDataTreeWriteTransa
                 treeService.createProducer(
                         Collections.singleton(new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, path))));
 
-        LOG.debug("{}: Creating DOMDataTreeCursorAwareTransactions delegates", txIdentifier, path);
+        LOG.debug("{}: Creating DOMDataTreeCursorAwareTransactions delegates on {}", txIdentifier, path);
         transactionMap.put(LogicalDatastoreType.CONFIGURATION,
                 producerMap.get(LogicalDatastoreType.CONFIGURATION).createTransaction(true));
         transactionMap.put(LogicalDatastoreType.OPERATIONAL,
index 13bd2932516763e5a4b3c3cced5ad74d9d5b12b6..eb172df890f3b5f08bd18b44e5c6d0a53c2ace82 100644 (file)
@@ -7,25 +7,17 @@
  */
 package org.opendaylight.mdsal.dom.broker;
 
-import com.google.common.util.concurrent.FluentFuture;
 import java.util.List;
 import java.util.Map;
 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
 import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
-import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
-import org.opendaylight.mdsal.dom.api.DOMRpcResult;
-import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 
 final class UnknownDOMRpcRoutingTableEntry extends AbstractDOMRpcRoutingTableEntry {
-    private final FluentFuture<DOMRpcResult> unknownRpc;
-
     UnknownDOMRpcRoutingTableEntry(final SchemaPath schemaPath, final Map<YangInstanceIdentifier,
             List<DOMRpcImplementation>> impls) {
         super(DOMRpcIdentifier.create(schemaPath), impls);
-        unknownRpc = FluentFutures.immediateFailedFluentFuture(
-            new DOMRpcImplementationNotAvailableException("SchemaPath %s is not resolved to an RPC", schemaPath));
     }
 
     @Override