mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-29 02:21:44 +00:00
Disable frivolous PMD warnings and enable PMD in ntcore (#3419)
Some valid warnings like throwing NullPointerException or using a for loop instead of System.arraycopy() were fixed. Abstract classes marked with PMD.AbstractClassWithoutAbstractMethod were made concrete because they already had protected constructors. Fixes #1697.
This commit is contained in:
@@ -853,6 +853,6 @@ public final class NetworkTableEntry {
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
private NetworkTableInstance m_inst;
|
||||
private int m_handle;
|
||||
private final NetworkTableInstance m_inst;
|
||||
private final int m_handle;
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
public NetworkTable getTable(String key) {
|
||||
// prepend leading / if not present
|
||||
String theKey;
|
||||
if (key.isEmpty() || key.equals("/")) {
|
||||
if (key.isEmpty() || "/".equals(key)) {
|
||||
theKey = "";
|
||||
} else if (key.charAt(0) == NetworkTable.PATH_SEPARATOR) {
|
||||
theKey = key;
|
||||
@@ -202,13 +202,13 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
|
||||
private final ReentrantLock m_entryListenerLock = new ReentrantLock();
|
||||
private final Map<Integer, EntryConsumer<EntryNotification>> m_entryListeners = new HashMap<>();
|
||||
private Thread m_entryListenerThread;
|
||||
private int m_entryListenerPoller;
|
||||
private boolean m_entryListenerWaitQueue;
|
||||
private final Condition m_entryListenerWaitQueueCond = m_entryListenerLock.newCondition();
|
||||
|
||||
@SuppressWarnings("PMD.AvoidCatchingThrowable")
|
||||
private void startEntryListenerThread() {
|
||||
m_entryListenerThread =
|
||||
var entryListenerThread =
|
||||
new Thread(
|
||||
() -> {
|
||||
boolean wasInterrupted = false;
|
||||
@@ -264,8 +264,8 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
}
|
||||
},
|
||||
"NTEntryListener");
|
||||
m_entryListenerThread.setDaemon(true);
|
||||
m_entryListenerThread.start();
|
||||
entryListenerThread.setDaemon(true);
|
||||
entryListenerThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -369,14 +369,14 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
private final ReentrantLock m_connectionListenerLock = new ReentrantLock();
|
||||
private final Map<Integer, Consumer<ConnectionNotification>> m_connectionListeners =
|
||||
new HashMap<>();
|
||||
private Thread m_connectionListenerThread;
|
||||
private int m_connectionListenerPoller;
|
||||
private boolean m_connectionListenerWaitQueue;
|
||||
private final Condition m_connectionListenerWaitQueueCond =
|
||||
m_connectionListenerLock.newCondition();
|
||||
|
||||
@SuppressWarnings("PMD.AvoidCatchingThrowable")
|
||||
private void startConnectionListenerThread() {
|
||||
m_connectionListenerThread =
|
||||
var connectionListenerThread =
|
||||
new Thread(
|
||||
() -> {
|
||||
boolean wasInterrupted = false;
|
||||
@@ -432,8 +432,8 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
}
|
||||
},
|
||||
"NTConnectionListener");
|
||||
m_connectionListenerThread.setDaemon(true);
|
||||
m_connectionListenerThread.start();
|
||||
connectionListenerThread.setDaemon(true);
|
||||
connectionListenerThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -519,13 +519,13 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
|
||||
private final ReentrantLock m_rpcCallLock = new ReentrantLock();
|
||||
private final Map<Integer, EntryConsumer<RpcAnswer>> m_rpcCalls = new HashMap<>();
|
||||
private Thread m_rpcCallThread;
|
||||
private int m_rpcCallPoller;
|
||||
private boolean m_rpcCallWaitQueue;
|
||||
private final Condition m_rpcCallWaitQueueCond = m_rpcCallLock.newCondition();
|
||||
|
||||
@SuppressWarnings("PMD.AvoidCatchingThrowable")
|
||||
private void startRpcCallThread() {
|
||||
m_rpcCallThread =
|
||||
var rpcCallThread =
|
||||
new Thread(
|
||||
() -> {
|
||||
boolean wasInterrupted = false;
|
||||
@@ -581,8 +581,8 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
}
|
||||
},
|
||||
"NTRpcCall");
|
||||
m_rpcCallThread.setDaemon(true);
|
||||
m_rpcCallThread.start();
|
||||
rpcCallThread.setDaemon(true);
|
||||
rpcCallThread.start();
|
||||
}
|
||||
|
||||
private static final byte[] rev0def = new byte[] {0};
|
||||
@@ -999,13 +999,13 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
|
||||
private final ReentrantLock m_loggerLock = new ReentrantLock();
|
||||
private final Map<Integer, Consumer<LogMessage>> m_loggers = new HashMap<>();
|
||||
private Thread m_loggerThread;
|
||||
private int m_loggerPoller;
|
||||
private boolean m_loggerWaitQueue;
|
||||
private final Condition m_loggerWaitQueueCond = m_loggerLock.newCondition();
|
||||
|
||||
@SuppressWarnings("PMD.AvoidCatchingThrowable")
|
||||
private void startLogThread() {
|
||||
m_loggerThread =
|
||||
var loggerThread =
|
||||
new Thread(
|
||||
() -> {
|
||||
boolean wasInterrupted = false;
|
||||
@@ -1049,8 +1049,8 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
}
|
||||
},
|
||||
"NTLogger");
|
||||
m_loggerThread.setDaemon(true);
|
||||
m_loggerThread.start();
|
||||
loggerThread.setDaemon(true);
|
||||
loggerThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1149,5 +1149,5 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
}
|
||||
|
||||
private boolean m_owned;
|
||||
private int m_handle;
|
||||
private final int m_handle;
|
||||
}
|
||||
|
||||
@@ -183,6 +183,7 @@ public final class NetworkTableValue {
|
||||
* @return The raw value.
|
||||
* @throws ClassCastException if the entry value is not of raw type.
|
||||
*/
|
||||
@SuppressWarnings("PMD.MethodReturnsInternalArray")
|
||||
public byte[] getRaw() {
|
||||
if (m_type != NetworkTableType.kRaw) {
|
||||
throw new ClassCastException("cannot convert " + m_type + " to raw");
|
||||
@@ -196,6 +197,7 @@ public final class NetworkTableValue {
|
||||
* @return The rpc definition value.
|
||||
* @throws ClassCastException if the entry value is not of rpc definition type.
|
||||
*/
|
||||
@SuppressWarnings("PMD.MethodReturnsInternalArray")
|
||||
public byte[] getRpc() {
|
||||
if (m_type != NetworkTableType.kRpc) {
|
||||
throw new ClassCastException("cannot convert " + m_type + " to rpc");
|
||||
@@ -209,6 +211,7 @@ public final class NetworkTableValue {
|
||||
* @return The boolean array value.
|
||||
* @throws ClassCastException if the entry value is not of boolean array type.
|
||||
*/
|
||||
@SuppressWarnings("PMD.MethodReturnsInternalArray")
|
||||
public boolean[] getBooleanArray() {
|
||||
if (m_type != NetworkTableType.kBooleanArray) {
|
||||
throw new ClassCastException("cannot convert " + m_type + " to boolean array");
|
||||
@@ -222,6 +225,7 @@ public final class NetworkTableValue {
|
||||
* @return The double array value.
|
||||
* @throws ClassCastException if the entry value is not of double array type.
|
||||
*/
|
||||
@SuppressWarnings("PMD.MethodReturnsInternalArray")
|
||||
public double[] getDoubleArray() {
|
||||
if (m_type != NetworkTableType.kDoubleArray) {
|
||||
throw new ClassCastException("cannot convert " + m_type + " to double array");
|
||||
@@ -235,6 +239,7 @@ public final class NetworkTableValue {
|
||||
* @return The string array value.
|
||||
* @throws ClassCastException if the entry value is not of string array type.
|
||||
*/
|
||||
@SuppressWarnings("PMD.MethodReturnsInternalArray")
|
||||
public String[] getStringArray() {
|
||||
if (m_type != NetworkTableType.kStringArray) {
|
||||
throw new ClassCastException("cannot convert " + m_type + " to string array");
|
||||
@@ -475,33 +480,25 @@ public final class NetworkTableValue {
|
||||
|
||||
static boolean[] toNative(Boolean[] arr) {
|
||||
boolean[] out = new boolean[arr.length];
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
out[i] = arr[i];
|
||||
}
|
||||
System.arraycopy(arr, 0, out, 0, arr.length);
|
||||
return out;
|
||||
}
|
||||
|
||||
static double[] toNative(Number[] arr) {
|
||||
double[] out = new double[arr.length];
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
out[i] = arr[i].doubleValue();
|
||||
}
|
||||
System.arraycopy(arr, 0, out, 0, arr.length);
|
||||
return out;
|
||||
}
|
||||
|
||||
static Boolean[] fromNative(boolean[] arr) {
|
||||
Boolean[] out = new Boolean[arr.length];
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
out[i] = arr[i];
|
||||
}
|
||||
System.arraycopy(arr, 0, out, 0, arr.length);
|
||||
return out;
|
||||
}
|
||||
|
||||
static Double[] fromNative(double[] arr) {
|
||||
Double[] out = new Double[arr.length];
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
out[i] = arr[i];
|
||||
}
|
||||
System.arraycopy(arr, 0, out, 0, arr.length);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ public final class RpcAnswer {
|
||||
* @param params Call raw parameters
|
||||
* @param conn Connection info
|
||||
*/
|
||||
@SuppressWarnings("PMD.ArrayIsStoredDirectly")
|
||||
public RpcAnswer(
|
||||
NetworkTableInstance inst,
|
||||
int entry,
|
||||
|
||||
@@ -41,7 +41,6 @@ class ConnectionListenerTest {
|
||||
}
|
||||
|
||||
/** Connect to the server. */
|
||||
@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
|
||||
private void connect() {
|
||||
m_serverInst.startServer("connectionlistenertest.ini", "127.0.0.1", 10000);
|
||||
m_clientInst.startClient("127.0.0.1", 10000);
|
||||
@@ -109,7 +108,6 @@ class ConnectionListenerTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@DisabledOnOs(OS.WINDOWS)
|
||||
@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
|
||||
@ValueSource(strings = {"127.0.0.1", "127.0.0.1 ", " 127.0.0.1 "})
|
||||
void testThreaded(String address) {
|
||||
m_serverInst.startServer("connectionlistenertest.ini", address, 10000);
|
||||
|
||||
@@ -34,7 +34,6 @@ class EntryListenerTest {
|
||||
m_serverInst.close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
|
||||
private void connect() {
|
||||
m_serverInst.startServer("connectionlistenertest.ini", "127.0.0.1", 10000);
|
||||
m_clientInst.startClient("127.0.0.1", 10000);
|
||||
|
||||
@@ -27,7 +27,6 @@ class LoggerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
|
||||
void addMessageTest() {
|
||||
List<LogMessage> msgs = new ArrayList<>();
|
||||
m_clientInst.addLogger(msgs::add, LogMessage.kInfo, 100);
|
||||
|
||||
Reference in New Issue
Block a user