Checkstyle rule to prevent throwing the generic RuntimeException
This is a frequent cause of sonar breakage.
Change-Id: I54e0044447633a61bab560b020b57ed0a6875ebe
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/ctl/SafeThriftClient.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/ctl/SafeThriftClient.java
index a510954..c1b83da 100644
--- a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/ctl/SafeThriftClient.java
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/ctl/SafeThriftClient.java
@@ -94,7 +94,8 @@
}
}
- throw new RuntimeException("Class needs to implement Iface directly. Use wrap(TServiceClient, Class) instead.");
+ throw new IllegalStateException(
+ "Class needs to implement Iface directly. Use wrap(TServiceClient, Class) instead.");
}
/**
@@ -202,7 +203,7 @@
Thread.sleep(timeBetweenRetries);
} catch (InterruptedException e2) {
Thread.currentThread().interrupt();
- throw new RuntimeException(e);
+ throw new IllegalStateException(e);
}
}
}
diff --git a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/impl/Bmv2PreGroupTranslatorImpl.java b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/impl/Bmv2PreGroupTranslatorImpl.java
index 6652ee0..369b7c5 100644
--- a/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/impl/Bmv2PreGroupTranslatorImpl.java
+++ b/drivers/bmv2/src/main/java/org/onosproject/drivers/bmv2/impl/Bmv2PreGroupTranslatorImpl.java
@@ -57,7 +57,7 @@
*/
public static Bmv2PreGroup translate(Group group) {
if (!group.type().equals(GroupDescription.Type.ALL)) {
- throw new RuntimeException("Unable to translate the group to BMv2 PRE group." +
+ throw new IllegalStateException("Unable to translate the group to BMv2 PRE group." +
"A BMv2 PRE group is to be of ALL type. GroupId="
+ group.id());
}
@@ -231,11 +231,11 @@
private static void checkOutputInstructions(GroupId groupId,
Set<Instructions.OutputInstruction> outputInstructions) {
if (outputInstructions.isEmpty()) {
- throw new RuntimeException(String.format("Group bucket contains no output instruction. GroupId=%s",
+ throw new IllegalStateException(String.format("Group bucket contains no output instruction. GroupId=%s",
groupId));
}
if (outputInstructions.size() != 1) {
- throw new RuntimeException(String.format("Group bucket contains more than one output instructions. " +
+ throw new IllegalStateException(String.format("Group bucket contains more than one output instructions. " +
"Only one is supported. GroupId=%s", groupId));
}
}
@@ -249,7 +249,7 @@
*/
private static void validatePort(PortNumber portNumber) {
if (portNumber.toLong() < 0 || portNumber.toLong() >= BMV2_PORT_MAP_SIZE) {
- throw new RuntimeException(String.format("Port number %d is not a valid BMv2 physical port number." +
+ throw new IllegalStateException(String.format("Port number %d is not a valid BMv2 physical port number." +
"Valid port range is [0,255]", portNumber));
}
}