Fix findbugs violations in md-sal - part 3 28/69328/3
authorTom Pantelis <tompantelis@gmail.com>
Fri, 9 Mar 2018 02:35:37 +0000 (21:35 -0500)
committerMichael Vorburger <vorburger@redhat.com>
Thu, 15 Mar 2018 23:01:30 +0000 (23:01 +0000)
- sal-binding-broker
- sal-connector-api
- sal-dummy-distributed-datastore
- messagebus-impl
- mdsal-trace-dom-impl

- May expose internal representation by returning reference to mutable object
- May expose internal representation by incorporating reference to mutable object
- Private method is never called
- Non-transient non-serializable instance field in serializable class
- Class is Serializable, but doesn't define serialVersionUID
- Parameter must be non-null but is marked as nullable
- Unread field
- Consider returning a zero length array rather than null
- Useless object created
- Method ignores return value
- Incorrect lazy initialization of static field
- Should be a static inner class

Change-Id: Ia8847db80bca98c6f7ff7aae267efc408a5dd8fd
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
15 files changed:
opendaylight/md-sal/mdsal-trace/dom-impl/src/main/java/org/opendaylight/controller/md/sal/trace/closetracker/impl/CloseTrackedRegistry.java
opendaylight/md-sal/mdsal-trace/dom-impl/src/main/java/org/opendaylight/controller/md/sal/trace/closetracker/impl/CloseTrackedTrait.java
opendaylight/md-sal/mdsal-trace/dom-impl/src/main/java/org/opendaylight/controller/md/sal/trace/dom/impl/TracingBroker.java
opendaylight/md-sal/mdsal-trace/dom-impl/src/main/java/org/opendaylight/controller/md/sal/trace/dom/impl/TracingReadOnlyTransaction.java
opendaylight/md-sal/mdsal-trace/dom-impl/src/main/java/org/opendaylight/controller/md/sal/trace/dom/impl/TracingTransactionChain.java
opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopic.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/compat/HeliumNotificationProviderServiceAdapter.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractForwardedDataBroker.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/FutureSchema.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/SingletonHolder.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RootBindingAwareBroker.java
opendaylight/md-sal/sal-connector-api/src/main/java/org/opendaylight/controller/sal/connector/api/BindingAwareRpcRouter.java
opendaylight/md-sal/sal-connector-api/src/main/java/org/opendaylight/controller/sal/connector/api/BindingAwareZeroMqRpcRouter.java
opendaylight/md-sal/sal-dummy-distributed-datastore/src/main/java/org/opendaylight/controller/dummy/datastore/DummyShard.java
opendaylight/md-sal/sal-dummy-distributed-datastore/src/main/java/org/opendaylight/controller/dummy/datastore/DummyShardManager.java

index 4e60839..78a09f1 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.controller.md.sal.trace.closetracker.impl;
 import static java.util.Arrays.asList;
 import static java.util.Collections.emptyList;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
@@ -87,6 +88,8 @@ public class CloseTrackedRegistry<T extends CloseTracked<T>> {
      *         debugContextEnabled is false), and value is the number of open
      *         instances created at that place in the code.
      */
+    // For some reason, FB sees 'map' as useless but it clearly isn't.
+    @SuppressFBWarnings("UC_USELESS_OBJECT")
     public Set<CloseTrackedRegistryReportEntry<T>> getAllUnique() {
         Map<List<StackTraceElement>, Long> map = new HashMap<>();
         Set<CloseTracked<T>> copyOfTracked = new HashSet<>(tracked);
index 4fe1e12..30e81c4 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.controller.md.sal.trace.closetracker.impl;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.Objects;
 import javax.annotation.Nullable;
 
@@ -45,6 +46,7 @@ public class CloseTrackedTrait<T extends CloseTracked<T>> implements CloseTracke
 
     @Override
     @Nullable
+    @SuppressFBWarnings("PZLA_PREFER_ZERO_LENGTH_ARRAYS")
     public StackTraceElement[] getAllocationContextStackTrace() {
         return allocationContext != null ? allocationContext.getStackTrace() : null;
     }
index d6b1039..02e65e7 100644 (file)
@@ -335,7 +335,7 @@ public class TracingBroker implements TracingDOMDataBroker {
 
     @Override
     public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
-        return new TracingReadOnlyTransaction(delegate.newReadOnlyTransaction(), this, readOnlyTransactionsRegistry);
+        return new TracingReadOnlyTransaction(delegate.newReadOnlyTransaction(), readOnlyTransactionsRegistry);
     }
 
     @Nonnull
index e275880..56e8d90 100644 (file)
@@ -22,13 +22,11 @@ class TracingReadOnlyTransaction
         implements DOMDataReadOnlyTransaction {
 
     private final DOMDataReadOnlyTransaction delegate;
-    private final TracingBroker tracingBroker;
 
-    TracingReadOnlyTransaction(DOMDataReadOnlyTransaction delegate, TracingBroker tracingBroker,
+    TracingReadOnlyTransaction(DOMDataReadOnlyTransaction delegate,
             CloseTrackedRegistry<TracingReadOnlyTransaction> readOnlyTransactionsRegistry) {
         super(readOnlyTransactionsRegistry);
         this.delegate = delegate;
-        this.tracingBroker = tracingBroker;
     }
 
     @Override
index b6f2fe0..2e5070f 100644 (file)
@@ -40,7 +40,7 @@ class TracingTransactionChain extends AbstractCloseTracked<TracingTransactionCha
     @SuppressWarnings("resource")
     public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
         final DOMDataReadOnlyTransaction tx = delegate.newReadOnlyTransaction();
-        return new TracingReadOnlyTransaction(tx, tracingBroker, readOnlyTransactionsRegistry);
+        return new TracingReadOnlyTransaction(tx, readOnlyTransactionsRegistry);
     }
 
     @Override
index 2a77807..fc4dad6 100644 (file)
@@ -20,6 +20,7 @@ import java.util.UUID;
 import java.util.concurrent.CopyOnWriteArraySet;
 import java.util.concurrent.ExecutionException;
 import java.util.regex.Pattern;
+import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
@@ -121,7 +122,7 @@ public final class EventSourceTopic implements DataTreeChangeListener<Node>, Aut
 
         Futures.addCallback(future, new FutureCallback<Optional<Topology>>() {
             @Override
-            public void onSuccess(final Optional<Topology> data) {
+            public void onSuccess(@Nonnull final Optional<Topology> data) {
                 if (data.isPresent()) {
                     final List<Node> nodes = data.get().getNode();
                     if (nodes != null) {
index a65d490..149c2c2 100644 (file)
@@ -17,7 +17,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class HeliumNotificationProviderServiceAdapter extends HeliumNotificationServiceAdapter
-        implements NotificationProviderService, AutoCloseable {
+        implements NotificationProviderService {
     private static final Logger LOG = LoggerFactory.getLogger(HeliumNotificationProviderServiceAdapter.class);
 
     private final NotificationPublishService notificationPublishService;
index da9cb2e..aff4a2b 100644 (file)
@@ -71,8 +71,7 @@ public abstract class AbstractForwardedDataBroker implements Delegator<DOMDataBr
         if (listener instanceof ClusteredDataChangeListener) {
             domDataChangeListener = new TranslatingClusteredDataChangeInvoker(store, path, listener, triggeringScope);
         } else {
-            domDataChangeListener = new TranslatingDataChangeInvoker(store, path, listener,
-                triggeringScope);
+            domDataChangeListener = new TranslatingDataChangeInvoker(path, listener);
         }
         final YangInstanceIdentifier domPath = codec.toYangInstanceIdentifierBlocking(path);
         final ListenerRegistration<DOMDataChangeListener> domRegistration =
@@ -130,16 +129,12 @@ public abstract class AbstractForwardedDataBroker implements Delegator<DOMDataBr
 
     private class TranslatingDataChangeInvoker implements DOMDataChangeListener {
         private final DataChangeListener bindingDataChangeListener;
-        private final LogicalDatastoreType store;
         private final InstanceIdentifier<?> path;
-        private final DataChangeScope triggeringScope;
 
-        TranslatingDataChangeInvoker(final LogicalDatastoreType store, final InstanceIdentifier<?> path,
-                final DataChangeListener bindingDataChangeListener, final DataChangeScope triggeringScope) {
-            this.store = store;
+        TranslatingDataChangeInvoker(final InstanceIdentifier<?> path,
+                final DataChangeListener bindingDataChangeListener) {
             this.path = path;
             this.bindingDataChangeListener = bindingDataChangeListener;
-            this.triggeringScope = triggeringScope;
         }
 
         @Override
@@ -161,7 +156,7 @@ public abstract class AbstractForwardedDataBroker implements Delegator<DOMDataBr
 
         TranslatingClusteredDataChangeInvoker(final LogicalDatastoreType store, final InstanceIdentifier<?> path,
                 final DataChangeListener bindingDataChangeListener, final DataChangeScope triggeringScope) {
-            super(store, path, bindingDataChangeListener, triggeringScope);
+            super(path, bindingDataChangeListener);
         }
     }
 
index 0c37839..5ee1f47 100644 (file)
@@ -18,6 +18,7 @@ import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
+import javax.annotation.Nonnull;
 import javax.annotation.concurrent.GuardedBy;
 import org.opendaylight.mdsal.binding.generator.util.BindingRuntimeContext;
 import org.opendaylight.yangtools.yang.binding.Augmentation;
@@ -90,7 +91,7 @@ class FutureSchema implements AutoCloseable {
     boolean waitForSchema(final QNameModule module) {
         return addPostponedOpAndWait(new FutureSchemaPredicate() {
             @Override
-            public boolean apply(final BindingRuntimeContext input) {
+            public boolean apply(@Nonnull final BindingRuntimeContext input) {
                 return input.getSchemaContext().findModule(module).isPresent();
             }
         });
index 6098684..13312b5 100644 (file)
@@ -131,7 +131,7 @@ public final class SingletonHolder {
         return COMMIT_EXECUTOR;
     }
 
-    public static ExecutorService getDefaultChangeEventExecutor() {
+    public static synchronized ExecutorService getDefaultChangeEventExecutor() {
         if (CHANGE_EVENT_EXECUTOR == null) {
             final ThreadFactory factory = new ThreadFactoryBuilder().setDaemon(true)
                     .setNameFormat("md-sal-binding-change-%d").build();
index f5f2b76..950384e 100644 (file)
@@ -188,7 +188,7 @@ public class RootBindingAwareBroker implements Mutable, Identifiable<String>, Bi
         return getRoot().registerRouteChangeListener(listener);
     }
 
-    public class RootSalInstance extends
+    public static class RootSalInstance extends
             AbstractBindingSalProviderInstance<NotificationProviderService, RpcProviderRegistry> {
 
         public RootSalInstance(final RpcProviderRegistry rpcRegistry,
index db10b08..22366f8 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.controller.sal.connector.api;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.concurrent.Future;
 import org.opendaylight.yangtools.concepts.Immutable;
 
@@ -16,6 +17,7 @@ public interface BindingAwareRpcRouter extends RpcRouter<String, String, String,
     Future<org.opendaylight.controller.sal.connector.api.RpcRouter.RpcReply<byte[]>> sendRpc(
             RpcRequest<String, String, String, byte[]> input);
 
+    @SuppressFBWarnings("EI_EXPOSE_REP2")
     class BindingAwareRequest implements RpcRequest<String, String, String, byte[]>, Immutable {
 
         private final BindingAwareRouteIdentifier routingInformation;
@@ -32,6 +34,7 @@ public interface BindingAwareRpcRouter extends RpcRouter<String, String, String,
         }
 
         @Override
+        @SuppressFBWarnings("EI_EXPOSE_REP")
         public byte[] getPayload() {
             return payload;
         }
index 71d56a7..27e403e 100644 (file)
@@ -29,10 +29,4 @@ public class BindingAwareZeroMqRpcRouter implements BindingAwareRpcRouter {
         return null;
     }
 
-    // Receiver part - invoked when request is received and deserialized
-    private Future<RpcReply<byte[]>> receivedRequest(RpcRequest<String, String, String, byte[]> input) {
-
-        return mdSalRouter.sendRpc(input);
-    }
-
 }
index db9515b..c5a3a03 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.controller.dummy.datastore;
 
 import akka.actor.Props;
 import akka.actor.UntypedActor;
-import akka.japi.Creator;
 import com.google.common.base.Stopwatch;
 import java.util.concurrent.TimeUnit;
 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
@@ -110,24 +109,6 @@ public class DummyShard extends UntypedActor {
     }
 
     public static Props props(Configuration configuration, final String followerId) {
-
-        return Props.create(new DummyShardCreator(configuration, followerId));
-    }
-
-    private static class DummyShardCreator implements Creator<DummyShard> {
-
-        private static final long serialVersionUID = 1L;
-        private final Configuration configuration;
-        private final String followerId;
-
-        DummyShardCreator(Configuration configuration, String followerId) {
-            this.configuration = configuration;
-            this.followerId = followerId;
-        }
-
-        @Override
-        public DummyShard create() throws Exception {
-            return new DummyShard(configuration, followerId);
-        }
+        return Props.create(DummyShard.class, configuration, followerId);
     }
 }
index abc73db..93d5c67 100644 (file)
@@ -11,7 +11,6 @@ package org.opendaylight.controller.dummy.datastore;
 import akka.actor.ActorContext;
 import akka.actor.Props;
 import akka.actor.UntypedActor;
-import akka.japi.Creator;
 
 public class DummyShardManager extends UntypedActor {
     public DummyShardManager(Configuration configuration, String memberName, String[] shardNames,
@@ -25,27 +24,7 @@ public class DummyShardManager extends UntypedActor {
     }
 
     public static Props props(Configuration configuration, String memberName, String[] shardNames, String type) {
-        return Props.create(new DummyShardManagerCreator(configuration, memberName, shardNames, type));
-    }
-
-    private static class DummyShardManagerCreator implements Creator<DummyShardManager> {
-
-        private final Configuration configuration;
-        private final String memberName;
-        private final String[] shardNames;
-        private final String type;
-
-        DummyShardManagerCreator(Configuration configuration, String memberName, String[] shardNames, String type) {
-            this.configuration = configuration;
-            this.memberName = memberName;
-            this.shardNames = shardNames;
-            this.type = type;
-        }
-
-        @Override
-        public DummyShardManager create() throws Exception {
-            return new DummyShardManager(configuration, memberName, shardNames, type);
-        }
+        return Props.create(DummyShardManager.class, configuration, memberName, shardNames, type);
     }
 
     private static class DummyShardsCreator {

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.