Fix FindBugs violations and enable enforcement in utils 37/65137/5
authorMichael Vorburger <vorburger@redhat.com>
Sat, 4 Nov 2017 03:31:25 +0000 (04:31 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 21 Nov 2017 09:28:57 +0000 (10:28 +0100)
Change-Id: I35eff969e51d6ec9b4f4b79b1b8cb2af9b9a8150
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
common/util/pom.xml
common/util/src/main/java/org/opendaylight/yangtools/util/MutableOffsetMap.java
common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/AsyncNotifyingListenableFutureTask.java
common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/CachedThreadPoolExecutor.java
common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ExceptionMapper.java
common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManager.java

index 5b713de7afc3b047f9dc05f833f6b9cbcdc39f54..b871d1ad38a5f7c9016b1bc76691dd4ade1aae65 100644 (file)
                     <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>findbugs-maven-plugin</artifactId>
+                <configuration>
+                    <failOnError>true</failOnError>
+                </configuration>
+           </plugin>
         </plugins>
     </build>
 
index 648b76d99f3c120211ad82241ee30e3e7d87138a..09511523bb901bf9abdedc36ca805d5410560eca 100644 (file)
@@ -13,6 +13,7 @@ import static java.util.Objects.requireNonNull;
 import com.google.common.annotations.Beta;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableMap;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.AbstractMap;
 import java.util.AbstractSet;
 import java.util.ArrayList;
@@ -119,6 +120,9 @@ public abstract class MutableOffsetMap<K, V> extends AbstractMap<K, V> implement
     private HashMap<K, V> newKeys;
     private Object[] objects;
     private int removed = 0;
+
+    // Fail-fast iterator guard, see java.util.ArrayList for reference.
+    @SuppressFBWarnings("VO_VOLATILE_INCREMENT")
     private transient volatile int modCount;
     private boolean needClone = true;
 
@@ -232,7 +236,7 @@ public abstract class MutableOffsetMap<K, V> extends AbstractMap<K, V> implement
     private void cloneArray() {
         if (needClone) {
             needClone = false;
-            if (!EMPTY_ARRAY.equals(objects)) {
+            if (objects.length != 0) {
                 objects = objects.clone();
             }
         }
index ec03529f7682febf6a5d264b10e6454f53166c93..ab3bdb1a09e154a1fe3ff5be321b71bb3055cd9f 100644 (file)
@@ -56,13 +56,13 @@ public class AsyncNotifyingListenableFutureTask<V> extends FutureTask<V> impleme
         private final Executor listenerExecutor;
 
         private DelegatingAsyncNotifyingListenableFutureTask(final Callable<V> callable,
-                @Nullable final Executor listenerExecutor) {
+                final Executor listenerExecutor) {
             super(callable);
             this.listenerExecutor = requireNonNull(listenerExecutor);
         }
 
         private DelegatingAsyncNotifyingListenableFutureTask(final Runnable runnable, @Nullable final V result,
-                @Nullable final Executor listenerExecutor) {
+                final Executor listenerExecutor) {
             super(runnable, result);
             this.listenerExecutor = requireNonNull(listenerExecutor);
         }
@@ -123,7 +123,7 @@ public class AsyncNotifyingListenableFutureTask<V> extends FutureTask<V> impleme
         super(callable);
     }
 
-    private AsyncNotifyingListenableFutureTask(final Runnable runnable, @Nullable final V result) {
+    private AsyncNotifyingListenableFutureTask(final Runnable runnable, final V result) {
         super(runnable, result);
     }
 
index cff95ff221075f23920ca1004a09e954e2852dce..112e84c74b6cbe04854e5254d2401a398eda9664 100644 (file)
@@ -11,6 +11,7 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.MoreObjects.ToStringHelper;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.RejectedExecutionException;
@@ -105,7 +106,7 @@ public class CachedThreadPoolExecutor extends ThreadPoolExecutor {
     }
 
     public long getLargestQueueSize() {
-        return ((TrackingLinkedBlockingQueue<?>)executorQueue.getBackingQueue()).getLargestQueueSize();
+        return executorQueue.getBackingQueue().getLargestQueueSize();
     }
 
     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
@@ -140,13 +141,14 @@ public class CachedThreadPoolExecutor extends ThreadPoolExecutor {
 
         private static final long POLL_WAIT_TIME_IN_MS = 300;
 
-        private final LinkedBlockingQueue<Runnable> backingQueue;
+        @SuppressFBWarnings("SE_BAD_FIELD") // Runnable is not Serializable
+        private final TrackingLinkedBlockingQueue<Runnable> backingQueue;
 
         ExecutorQueue(final int maxBackingQueueSize) {
             backingQueue = new TrackingLinkedBlockingQueue<>(maxBackingQueueSize);
         }
 
-        LinkedBlockingQueue<Runnable> getBackingQueue() {
+        TrackingLinkedBlockingQueue<Runnable> getBackingQueue() {
             return backingQueue;
         }
 
index 53e0936214b4f3598be185ea3787154b93eca3f2..e3a7559a587e0d22919581299fb04482411aa0c9 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.yangtools.util.concurrent;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.base.Function;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.concurrent.CancellationException;
 import java.util.concurrent.ExecutionException;
 
@@ -71,8 +72,9 @@ public abstract class ExceptionMapper<X extends Exception> implements Function<E
      */
     protected abstract X newWithCause(String message, Throwable cause);
 
-    @SuppressWarnings("unchecked")
     @Override
+    @SuppressWarnings("unchecked")
+    @SuppressFBWarnings({"BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", "NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE"})
     public X apply(final Exception input) {
 
         // If exception is of the specified type,return it.
index 2942799556ebeecc6babb2829c2c5e5f8a1921ee..8b2f4737aa6a917133c7b577ae959807964d170d 100644 (file)
@@ -311,7 +311,7 @@ public class QueuedNotificationManager<L, N> implements NotificationManager<L, N
         NotificationTask(final ListenerKey<L> listenerKey, final Iterator<N> notifications) {
             this.listenerKey = requireNonNull(listenerKey);
             while (notifications.hasNext()) {
-                queue.offer(notifications.next());
+                queue.add(notifications.next());
             }
         }
 
@@ -368,7 +368,7 @@ public class QueuedNotificationManager<L, N> implements NotificationManager<L, N
                             return true;
                         }
 
-                        queue.offer(notifications.next());
+                        queue.add(notifications.next());
                     }
                 }
             } finally {