Change RTE to an ISE 39/101139/5
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 16 May 2022 09:03:29 +0000 (11:03 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 17 May 2022 23:08:22 +0000 (01:08 +0200)
SpotBugs does not like our throwuign a plain RuntimeException, throw an
ISE instead.

Change-Id: I1d900144757294df2ebd5b230010cf654372cfcb
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
21 files changed:
benchmark/ntfbenchmark/src/main/java/ntfbenchmark/impl/NtfbenchNonblockingProducer.java
opendaylight/md-sal/sal-akka-raft-example/src/main/java/org/opendaylight/controller/cluster/example/ExampleActor.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderInstallSnapshotState.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractDataStoreClientActor.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractDataStoreClientBehavior.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransaction.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalReadWriteProxyTransaction.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractDataStore.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CohortEntry.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardCommitCoordinator.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeListenerInfoMXBeanImpl.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/AbortTransactionPayload.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/CloseLocalHistoryPayload.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/CreateLocalHistoryPayload.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/DisableTrackingPayload.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/PurgeLocalHistoryPayload.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/PurgeTransactionPayload.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/SkipTransactionsPayload.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManagerInfo.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/DataTreeModificationOutput.java
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/mbeans/AbstractRegistryMXBean.java

index b0e239c4d45f99f483c7abbd1ae681d98498f723..4b44e1d73dbf2f25bffbd3b4de47f83c03e38f10 100644 (file)
@@ -28,9 +28,9 @@ public class NtfbenchNonblockingProducer extends AbstractNtfbenchProducer {
         int ntfOk = 0;
         int ntfError = 0;
         ListenableFuture<?> lastOkFuture = null;
-        for (int i = 0; i < this.iterations; i++) {
+        for (int i = 0; i < iterations; i++) {
             try {
-                final ListenableFuture<?> result = this.publishService.offerNotification(this.ntf);
+                final ListenableFuture<?> result = publishService.offerNotification(ntf);
                 if (NotificationPublishService.REJECTED == result) {
                     ntfError++;
                 } else {
@@ -50,9 +50,8 @@ public class NtfbenchNonblockingProducer extends AbstractNtfbenchProducer {
             try {
                 lastOkFuture.get();
             } catch (InterruptedException | ExecutionException e) {
-                throw new RuntimeException(e);
+                throw new IllegalStateException(e);
             }
         }
     }
-
 }
index 17d6f980cd3d1836b763f160186e7acdb1b7f54a..50eda52aeaa6b76bc2a6716f53b790d9a8f2f8c5 100644 (file)
@@ -202,7 +202,7 @@ public class ExampleActor extends RaftActor implements RaftActorRecoveryCohort,
         try {
             return new MapState((Map<String, String>) SerializationUtils.deserialize(snapshotBytes.read()));
         } catch (IOException e) {
-            throw new RuntimeException(e);
+            throw new IllegalStateException(e);
         }
     }
 
index cc4caa32ebacc8511fd4ea610ea6af2af2e53bf4..e7c76bacbeaa539c2d91488a3c9b305f7dae04e1 100644 (file)
@@ -183,7 +183,7 @@ public final class LeaderInstallSnapshotState implements AutoCloseable {
         try {
             snapshotInputStream = snapshotBytes.openStream();
         } catch (IOException e) {
-            throw new RuntimeException(e);
+            throw new IllegalStateException(e);
         }
     }
 
index e5d8abcb629826b4a505b3eef08136052bc57ec8..507f065d49cfe370d589326bdb92bbc37a477844 100644 (file)
@@ -12,6 +12,7 @@ import static java.util.Objects.requireNonNull;
 
 import akka.actor.ActorRef;
 import akka.util.Timeout;
+import com.google.common.base.Throwables;
 import java.util.concurrent.TimeUnit;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.controller.cluster.access.client.AbstractClientActor;
@@ -53,10 +54,9 @@ public abstract class AbstractDataStoreClientActor extends AbstractClientActor {
         try {
             return (DataStoreClient) Await.result(ExplicitAsk.ask(actor, GET_CLIENT_FACTORY,
                 Timeout.apply(timeout, unit)), Duration.Inf());
-        } catch (RuntimeException e) {
-            throw e;
         } catch (Exception e) {
-            throw new RuntimeException(e);
+            Throwables.throwIfUnchecked(e);
+            throw new IllegalStateException(e);
         }
     }
 }
index 7187f83a1ac060d41341c110181877b9535b2985..82567c40d930c2300407eb710cbe1d40b89fa022 100644 (file)
@@ -195,7 +195,7 @@ abstract class AbstractDataStoreClientBehavior extends ClientActorBehavior<Shard
         try {
             if (aborted != null) {
                 Throwables.throwIfUnchecked(aborted);
-                throw new RuntimeException(aborted);
+                throw new IllegalStateException(aborted);
             }
 
             final ClientLocalHistory history = new ClientLocalHistory(this, historyId);
index 471e322a81a343c77912955b36eda51ead75524e..9b9b86f11b84b04bda361e1b56ad837a60c393db 100644 (file)
@@ -141,7 +141,7 @@ abstract class AbstractProxyTransaction implements Identifiable<TransactionIdent
                 latch.await();
             } catch (InterruptedException e) {
                 LOG.warn("Interrupted while waiting for latch of {}", successor);
-                throw new RuntimeException(e);
+                throw new IllegalStateException(e);
             }
             return successor;
         }
index 7fcaf4e953e1410b8b3c57c4fe4f83c77521a34d..ab7cdbc9fa1e5cd4172185ef50722da805135ebd 100644 (file)
@@ -12,6 +12,7 @@ import static com.google.common.base.Verify.verify;
 import static com.google.common.base.Verify.verifyNotNull;
 
 import com.google.common.util.concurrent.FluentFuture;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.Optional;
 import java.util.OptionalLong;
 import java.util.function.BiConsumer;
@@ -96,8 +97,7 @@ final class LocalReadWriteProxyTransaction extends LocalProxyTransaction {
             final DataTreeSnapshot snapshot) {
         super(parent, identifier, false);
 
-        if (snapshot instanceof FailedDataTreeModification) {
-            final var failed = (FailedDataTreeModification) snapshot;
+        if (snapshot instanceof FailedDataTreeModification failed) {
             recordedFailure = failed.cause();
             modification = failed;
         } else {
@@ -407,6 +407,7 @@ final class LocalReadWriteProxyTransaction extends LocalProxyTransaction {
         closedException = this::abortedException;
     }
 
+    @SuppressFBWarnings(value = "THROWS_METHOD_THROWS_RUNTIMEEXCEPTION", justification = "Replay of recorded failure")
     private @NonNull CursorAwareDataTreeModification getModification() {
         if (closedException != null) {
             throw closedException.get();
index cf60b089d832a8b0c2bf6a9f1c1d76443c119204..96b1b4a1945d81b57bbe7246982caff2ee55caf0 100644 (file)
@@ -112,7 +112,7 @@ public abstract class AbstractDataStore implements DistributedDataStoreInterface
             LOG.error("Failed to get actor for {}", clientProps, e);
             clientActor.tell(PoisonPill.getInstance(), ActorRef.noSender());
             Throwables.throwIfUnchecked(e);
-            throw new RuntimeException(e);
+            throw new IllegalStateException(e);
         }
 
         identifier = client.getIdentifier();
index de325279b7a1aa252ca403e7d8034b981486efb5..792aacc3d5c5f8475e9920085932bf5f0aa639a6 100644 (file)
@@ -13,6 +13,7 @@ import static java.util.Objects.requireNonNull;
 import akka.actor.ActorRef;
 import com.google.common.primitives.UnsignedLong;
 import com.google.common.util.concurrent.FutureCallback;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.List;
 import java.util.Optional;
 import java.util.SortedSet;
@@ -91,6 +92,7 @@ final class CohortEntry {
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
+    @SuppressFBWarnings(value = "THROWS_METHOD_THROWS_RUNTIMEEXCEPTION", justification = "Re-thrown")
     void applyModifications(final List<Modification> modifications) {
         totalBatchedModificationsReceived++;
         if (lastBatchedModificationsException == null) {
index 5177f7ed2bcbaee7d03b53a894c5279d17a3f9f2..29e254e6170f614916c063d089803e6c99568600 100644 (file)
@@ -15,6 +15,7 @@ import akka.serialization.Serialization;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.primitives.UnsignedLong;
 import com.google.common.util.concurrent.FutureCallback;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -129,6 +130,7 @@ final class ShardCommitCoordinator {
      * @param batched the BatchedModifications message to process
      * @param sender the sender of the message
      */
+    @SuppressFBWarnings(value = "THROWS_METHOD_THROWS_RUNTIMEEXCEPTION", justification = "Replay of captured failure")
     void handleBatchedModifications(final BatchedModifications batched, final ActorRef sender, final Shard shard) {
         CohortEntry cohortEntry = cohortCache.get(batched.getTransactionId());
         if (cohortEntry == null || cohortEntry.isSealed()) {
index 060c28ae1d44385b6e54dc21b60b4031f53233dd..cab0c534ac90819e48b93ed2c26a9264f0c2ba20 100644 (file)
@@ -58,7 +58,7 @@ final class ShardDataTreeListenerInfoMXBeanImpl extends AbstractMXBean implement
             return stateCache.get();
         } catch (Exception e) {
             Throwables.throwIfUnchecked(e);
-            throw new RuntimeException(e);
+            throw new IllegalStateException(e);
         }
     }
 
@@ -67,7 +67,7 @@ final class ShardDataTreeListenerInfoMXBeanImpl extends AbstractMXBean implement
     private static List<DataTreeListenerInfo> getListenerActorsInfo(final Collection<ActorSelection> actors) {
         final Timeout timeout = new Timeout(20, TimeUnit.SECONDS);
         final List<Future<Object>> futureList = new ArrayList<>(actors.size());
-        for (ActorSelection actor: actors) {
+        for (ActorSelection actor : actors) {
             futureList.add(Patterns.ask(actor, GetInfo.INSTANCE, timeout));
         }
 
index 0e34756cede02dfef04496f4f2e1f4066391b220..0931b91ac7b524d2e8f0ccfefd068af18210ee19 100644 (file)
@@ -62,7 +62,7 @@ public final class AbortTransactionPayload extends AbstractIdentifiablePayload<T
         } catch (IOException e) {
             // This should never happen
             LOG.error("Failed to serialize {}", transactionId, e);
-            throw new RuntimeException("Failed to serialized " + transactionId, e);
+            throw new IllegalStateException("Failed to serialized " + transactionId, e);
         }
         return new AbortTransactionPayload(transactionId, out.toByteArray());
     }
index 9acc113a422b9b962e122a5ad11c94c43c69be3b..1921ff889fa99998330cdca94b5ee93a98961bb6 100644 (file)
@@ -62,7 +62,7 @@ public final class CloseLocalHistoryPayload extends AbstractIdentifiablePayload<
         } catch (IOException e) {
             // This should never happen
             LOG.error("Failed to serialize {}", historyId, e);
-            throw new RuntimeException("Failed to serialize " + historyId, e);
+            throw new IllegalStateException("Failed to serialize " + historyId, e);
         }
         return new CloseLocalHistoryPayload(historyId, out.toByteArray());
     }
index dbf72f38d8de0f0016a4651c3ef46fcebe5e4760..76ea934cb42433c7ff833346e302e3a308f271c9 100644 (file)
@@ -62,7 +62,7 @@ public final class CreateLocalHistoryPayload extends AbstractIdentifiablePayload
         } catch (IOException e) {
             // This should never happen
             LOG.error("Failed to serialize {}", historyId, e);
-            throw new RuntimeException("Failed to serialize " + historyId, e);
+            throw new IllegalStateException("Failed to serialize " + historyId, e);
         }
         return new CreateLocalHistoryPayload(historyId, out.toByteArray());
     }
index 29dd0725245e761a2551a2cf00bab41b6c6e35f8..c5c6375ff267e8ddd72b9d047cfd0cfcd4e21945 100644 (file)
@@ -53,7 +53,7 @@ public final class DisableTrackingPayload extends AbstractIdentifiablePayload<Cl
         } catch (IOException e) {
             // This should never happen
             LOG.error("Failed to serialize {}", clientId, e);
-            throw new RuntimeException("Failed to serialize " + clientId, e);
+            throw new IllegalStateException("Failed to serialize " + clientId, e);
         }
         return new DisableTrackingPayload(clientId, out.toByteArray());
     }
index 8d9a8d217a67e201dda8c8f9ba9f705ac939557c..4e3ca254a94051e3e5e8bb843c02d681d7fcdedf 100644 (file)
@@ -63,7 +63,7 @@ public final class PurgeLocalHistoryPayload extends AbstractIdentifiablePayload<
         } catch (IOException e) {
             // This should never happen
             LOG.error("Failed to serialize {}", historyId, e);
-            throw new RuntimeException("Failed to serialize " + historyId, e);
+            throw new IllegalStateException("Failed to serialize " + historyId, e);
         }
         return new PurgeLocalHistoryPayload(historyId, out.toByteArray());
     }
index ac849723e168b1b439c1a90dd4f4b9f87504a07d..725189e5fc64864f14eb478a0b960eada435fa4a 100644 (file)
@@ -62,7 +62,7 @@ public final class PurgeTransactionPayload extends AbstractIdentifiablePayload<T
         } catch (IOException e) {
             // This should never happen
             LOG.error("Failed to serialize {}", transactionId, e);
-            throw new RuntimeException("Failed to serialize " + transactionId, e);
+            throw new IllegalStateException("Failed to serialize " + transactionId, e);
         }
         return new PurgeTransactionPayload(transactionId, out.toByteArray());
     }
index ec6e227a75a91bf672fb081a796c381b14754b48..70daab692a80b77ceb86051f86740c1676d1a550 100644 (file)
@@ -77,7 +77,7 @@ public final class SkipTransactionsPayload extends AbstractIdentifiablePayload<L
         } catch (IOException e) {
             // This should never happen
             LOG.error("Failed to serialize {} ids {}", historyId, transactionIds, e);
-            throw new RuntimeException("Failed to serialize " + historyId + " ids " + transactionIds, e);
+            throw new IllegalStateException("Failed to serialize " + historyId + " ids " + transactionIds, e);
         }
 
         return new SkipTransactionsPayload(historyId, out.toByteArray(), transactionIds);
index 244b0a186cdaba4b3400a5be8dcc3d08e08d30ae..8577a5914c0389905f9f55d4fff8fb496ac91cff 100644 (file)
@@ -11,6 +11,7 @@ import static java.util.Objects.requireNonNull;
 
 import akka.actor.ActorRef;
 import akka.pattern.Patterns;
+import com.google.common.base.Throwables;
 import java.util.List;
 import org.opendaylight.controller.cluster.access.concepts.MemberName;
 import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
@@ -47,10 +48,9 @@ final class ShardManagerInfo extends AbstractMXBean implements ShardManagerInfoM
         try {
             return (List<String>) Await.result(
                 Patterns.ask(shardManager, GetLocalShardIds.INSTANCE, ASK_TIMEOUT_MILLIS), Duration.Inf());
-        } catch (RuntimeException e) {
-            throw e;
         } catch (Exception e) {
-            throw new RuntimeException(e);
+            Throwables.throwIfUnchecked(e);
+            throw new IllegalStateException(e);
         }
     }
 
@@ -80,10 +80,9 @@ final class ShardManagerInfo extends AbstractMXBean implements ShardManagerInfoM
                 try {
                     Await.result(Patterns.ask(shardManager, new SwitchShardBehavior(shardId, state, term),
                         ASK_TIMEOUT_MILLIS), Duration.Inf());
-                } catch (RuntimeException e) {
-                    throw e;
                 } catch (Exception e) {
-                    throw new RuntimeException(e);
+                    Throwables.throwIfUnchecked(e);
+                    throw new IllegalStateException(e);
                 }
                 break;
             case Candidate:
index 3619c2264e142c9bcc3259846569124bb4341c75..5b073e856f6f163daf7af51f197f4b194ee04016 100644 (file)
@@ -54,7 +54,7 @@ public final class DataTreeModificationOutput {
                 output.write(current().node(child).toString().getBytes(StandardCharsets.UTF_8));
                 output.writeByte('\n');
             } catch (IOException e) {
-                throw new RuntimeException(e);
+                throw new IllegalStateException(e);
             }
         }
 
@@ -78,7 +78,7 @@ public final class DataTreeModificationOutput {
                 NormalizedNodeXMLOutput.toStream(output, data);
                 output.writeByte('\n');
             } catch (IOException | XMLStreamException e) {
-                throw new RuntimeException(e);
+                throw new IllegalStateException(e);
             }
         }
     }
index 6bf195d093dba3ea2b1f42a505c88865fdac19d5..a38b8c4d890903f834c7fb33238ee13139e7cc4a 100644 (file)
@@ -13,6 +13,7 @@ import akka.actor.Address;
 import akka.util.Timeout;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.Map;
+import java.util.concurrent.TimeoutException;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean;
 import org.opendaylight.controller.remote.rpc.registry.AbstractRoutingTable;
@@ -45,30 +46,30 @@ abstract class AbstractRegistryMXBean<T extends AbstractRoutingTable<T, I>, I> e
         registerMBean();
     }
 
-    @SuppressWarnings({"unchecked", "checkstyle:IllegalCatch", "rawtypes"})
+    @SuppressWarnings({"unchecked", "rawtypes"})
     final T localData() {
         try {
             return (T) Await.result((Future) bucketAccess.getLocalData(), timeout);
-        } catch (Exception e) {
-            throw new RuntimeException("getLocalData failed", e);
+        } catch (InterruptedException | TimeoutException e) {
+            throw new IllegalStateException("getLocalData failed", e);
         }
     }
 
-    @SuppressWarnings({"unchecked", "checkstyle:IllegalCatch", "rawtypes"})
+    @SuppressWarnings({"unchecked", "rawtypes"})
     final Map<Address, Bucket<T>> remoteBuckets() {
         try {
             return (Map<Address, Bucket<T>>) Await.result((Future)bucketAccess.getRemoteBuckets(), timeout);
-        } catch (Exception e) {
-            throw new RuntimeException("getRemoteBuckets failed", e);
+        } catch (InterruptedException | TimeoutException e) {
+            throw new IllegalStateException("getRemoteBuckets failed", e);
         }
     }
 
-    @SuppressWarnings({"unchecked", "checkstyle:IllegalCatch", "rawtypes"})
+    @SuppressWarnings({"unchecked", "rawtypes"})
     final String bucketVersions() {
         try {
             return Await.result((Future)bucketAccess.getBucketVersions(), timeout).toString();
-        } catch (Exception e) {
-            throw new RuntimeException("getVersions failed", e);
+        } catch (InterruptedException | TimeoutException e) {
+            throw new IllegalStateException("getVersions failed", e);
         }
     }
 }