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:
Tyler Veness
2021-06-09 07:01:00 -07:00
committed by GitHub
parent 8284075ee4
commit c1e128bd5a
93 changed files with 154 additions and 326 deletions

View File

@@ -21,7 +21,6 @@ import java.nio.ByteOrder;
*
* <p>This class allows access to an Analog Devices ADXL362 3-axis accelerometer.
*/
@SuppressWarnings("PMD.UnusedPrivateField")
public class ADXL362 implements Accelerometer, Sendable, AutoCloseable {
private static final byte kRegWrite = 0x0A;
private static final byte kRegRead = 0x0B;
@@ -37,7 +36,10 @@ public class ADXL362 implements Accelerometer, Sendable, AutoCloseable {
private static final byte kFilterCtl_ODR_100Hz = 0x03;
private static final byte kPowerCtl_UltraLowNoise = 0x20;
@SuppressWarnings("PMD.UnusedPrivateField")
private static final byte kPowerCtl_AutoSleep = 0x04;
private static final byte kPowerCtl_Measure = 0x02;
public enum Axes {

View File

@@ -163,7 +163,6 @@ public class DigitalGlitchFilter implements Sendable, AutoCloseable {
}
@Override
@SuppressWarnings("PMD.UnusedFormalParameter")
public void initSendable(SendableBuilder builder) {}
private int m_channelIndex = -1;

View File

@@ -18,13 +18,6 @@ import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/** Provide access to the network communication data to / from the Driver Station. */
@SuppressWarnings({
"PMD.CyclomaticComplexity",
"PMD.ExcessiveClassLength",
"PMD.ExcessivePublicCount",
"PMD.GodClass",
"PMD.TooManyFields"
})
public class DriverStation {
/** Number of Joystick Ports. */
public static final int kJoystickPorts = 6;
@@ -162,7 +155,6 @@ public class DriverStation {
controlWord.forceSetDouble(0);
}
@SuppressWarnings("PMD.NPathComplexity")
private void sendMatchData(DriverStation driverStation) {
AllianceStationID allianceID = HAL.getAllianceStation();
boolean isRedAlliance = false;
@@ -268,8 +260,7 @@ public class DriverStation {
private final MatchDataSender m_matchDataSender;
// Internal Driver Station thread
@SuppressWarnings("PMD.SingularField")
private final Thread m_thread;
private Thread m_thread;
private volatile boolean m_threadKeepAlive = true;
@@ -308,7 +299,6 @@ public class DriverStation {
* <p>The single DriverStation instance is created statically with the instance static member
* variable.
*/
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
private DriverStation() {
HAL.initialize(500, 0);
m_waitForDataCount = 0;
@@ -340,6 +330,14 @@ public class DriverStation {
/** Kill the thread. */
public void release() {
m_threadKeepAlive = false;
if (m_thread != null) {
try {
m_thread.join();
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
m_thread = null;
}
}
/**

View File

@@ -18,7 +18,6 @@ import java.nio.ByteBuffer;
* <p>This class is intended to be used by sensor (and other I2C device) drivers. It probably should
* not be used directly.
*/
@SuppressWarnings("PMD.GodClass")
public class I2C implements AutoCloseable {
public enum Port {
kOnboard(0),
@@ -99,7 +98,7 @@ public class I2C implements AutoCloseable {
* @param receiveSize Number of bytes to read from the device.
* @return Transfer Aborted... false for success, true for aborted.
*/
@SuppressWarnings({"PMD.CyclomaticComplexity", "ByteBufferBackingArray"})
@SuppressWarnings("ByteBufferBackingArray")
public synchronized boolean transaction(
ByteBuffer dataToSend, int sendSize, ByteBuffer dataReceived, int receiveSize) {
if (dataToSend.hasArray() && dataReceived.hasArray()) {

View File

@@ -208,7 +208,6 @@ public abstract class IterativeRobotBase extends RobotBase {
return m_period;
}
@SuppressWarnings("PMD.CyclomaticComplexity")
protected void loopFunc() {
m_watchdog.reset();

View File

@@ -163,7 +163,6 @@ public class Relay extends MotorSafety implements Sendable, AutoCloseable {
*
* @param value The state to set the relay.
*/
@SuppressWarnings("PMD.CyclomaticComplexity")
public void set(Value value) {
switch (value) {
case kOff:

View File

@@ -277,10 +277,7 @@ public abstract class RobotBase implements AutoCloseable {
private static boolean m_suppressExitWarning;
/** Run the robot main loop. */
@SuppressWarnings({
"PMD.AvoidInstantiatingObjectsInLoops", "PMD.AvoidCatchingThrowable",
"PMD.CyclomaticComplexity", "PMD.NPathComplexity"
})
@SuppressWarnings("PMD.AvoidCatchingThrowable")
private static <T extends RobotBase> void runRobot(Supplier<T> robotSupplier) {
System.out.println("********** Robot program starting **********");

View File

@@ -13,7 +13,6 @@ import java.nio.ByteOrder;
import java.nio.IntBuffer;
/** Represents a SPI bus port. */
@SuppressWarnings("PMD.CyclomaticComplexity")
public class SPI implements AutoCloseable {
public enum Port {
kOnboardCS0(0),
@@ -258,7 +257,7 @@ public class SPI implements AutoCloseable {
* @param dataReceived Buffer to receive data from the device.
* @param size The length of the transaction, in bytes
*/
@SuppressWarnings({"PMD.CyclomaticComplexity", "ByteBufferBackingArray"})
@SuppressWarnings("ByteBufferBackingArray")
public int transaction(ByteBuffer dataToSend, ByteBuffer dataReceived, int size) {
if (dataToSend.hasArray() && dataReceived.hasArray()) {
return transaction(dataToSend.array(), dataReceived.array(), size);
@@ -425,7 +424,6 @@ public class SPI implements AutoCloseable {
private static final int kAccumulateDepth = 2048;
@SuppressWarnings("PMD.TooManyFields")
private static class Accumulator implements AutoCloseable {
Accumulator(
int port,
@@ -482,7 +480,6 @@ public class SPI implements AutoCloseable {
final boolean m_bigEndian; // is response big endian?
final int m_port;
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
void update() {
synchronized (m_mutex) {
boolean done = false;

View File

@@ -26,14 +26,11 @@ public class SpeedControllerGroup implements MotorController, Sendable, AutoClos
*
* @param speedControllers The SpeedControllers to add
*/
@SuppressWarnings("PMD.AvoidArrayLoops")
public SpeedControllerGroup(
SpeedController speedController, SpeedController... speedControllers) {
m_speedControllers = new SpeedController[speedControllers.length + 1];
m_speedControllers[0] = speedController;
for (int i = 0; i < speedControllers.length; i++) {
m_speedControllers[i + 1] = speedControllers[i];
}
System.arraycopy(speedControllers, 0, m_speedControllers, 1, speedControllers.length);
init();
}

View File

@@ -28,7 +28,7 @@ public class XboxController extends GenericHID {
kBack(7),
kStart(8);
@SuppressWarnings({"MemberName", "PMD.SingularField"})
@SuppressWarnings("MemberName")
public final int value;
Button(int value) {
@@ -45,7 +45,7 @@ public class XboxController extends GenericHID {
kLeftTrigger(2),
kRightTrigger(3);
@SuppressWarnings({"MemberName", "PMD.SingularField"})
@SuppressWarnings("MemberName")
public final int value;
Axis(int value) {

View File

@@ -12,7 +12,6 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
/** Implements a PID control loop. */
@SuppressWarnings("PMD.TooManyFields")
public class PIDController implements Sendable, AutoCloseable {
private static int instances;

View File

@@ -4,6 +4,8 @@
package edu.wpi.first.wpilibj.drive;
import static java.util.Objects.requireNonNull;
import edu.wpi.first.hal.FRCNetComm.tInstances;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
@@ -12,7 +14,6 @@ import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import java.util.StringJoiner;
/**
* A class for driving differential drive/skid-steer drive platforms such as the Kit of Parts drive
@@ -121,7 +122,9 @@ public class DifferentialDrive extends RobotDriveBase implements Sendable, AutoC
* so before passing it in.
*/
public DifferentialDrive(SpeedController leftMotor, SpeedController rightMotor) {
verify(leftMotor, rightMotor);
requireNonNull(leftMotor, "Left motor cannot be null");
requireNonNull(rightMotor, "Right motor cannot be null");
m_leftMotor = leftMotor;
m_rightMotor = rightMotor;
SendableRegistry.addChild(this, m_leftMotor);
@@ -135,29 +138,6 @@ public class DifferentialDrive extends RobotDriveBase implements Sendable, AutoC
SendableRegistry.remove(this);
}
/**
* Verifies that all motors are nonnull, throwing a NullPointerException if any of them are. The
* exception's error message will specify all null motors, e.g. {@code
* NullPointerException("leftMotor, rightMotor")}, to give as much information as possible to the
* programmer.
*
* @throws NullPointerException if any of the given motors are null
*/
@SuppressWarnings("PMD.AvoidThrowingNullPointerException")
private void verify(SpeedController leftMotor, SpeedController rightMotor) {
if (leftMotor != null && rightMotor != null) {
return;
}
StringJoiner joiner = new StringJoiner(", ");
if (leftMotor == null) {
joiner.add("leftMotor");
}
if (rightMotor == null) {
joiner.add("rightMotor");
}
throw new NullPointerException(joiner.toString());
}
/**
* Arcade drive method for differential drive platform. The calculated values will be squared to
* decrease sensitivity at low speeds.
@@ -212,7 +192,7 @@ public class DifferentialDrive extends RobotDriveBase implements Sendable, AutoC
* @param allowTurnInPlace If set, overrides constant-curvature turning for turn-in-place
* maneuvers.
*/
@SuppressWarnings({"ParameterName", "PMD.CyclomaticComplexity"})
@SuppressWarnings("ParameterName")
public void curvatureDrive(double xSpeed, double zRotation, boolean allowTurnInPlace) {
if (!m_reported) {
HAL.report(

View File

@@ -4,6 +4,8 @@
package edu.wpi.first.wpilibj.drive;
import static java.util.Objects.requireNonNull;
import edu.wpi.first.hal.FRCNetComm.tInstances;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
@@ -12,7 +14,6 @@ import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import java.util.StringJoiner;
/**
* A class for driving Killough drive platforms.
@@ -122,7 +123,10 @@ public class KilloughDrive extends RobotDriveBase implements Sendable, AutoClose
double leftMotorAngle,
double rightMotorAngle,
double backMotorAngle) {
verify(leftMotor, rightMotor, backMotor);
requireNonNull(leftMotor, "Left motor cannot be null");
requireNonNull(rightMotor, "Right motor cannot be null");
requireNonNull(backMotor, "Back motor cannot be null");
m_leftMotor = leftMotor;
m_rightMotor = rightMotor;
m_backMotor = backMotor;
@@ -150,33 +154,6 @@ public class KilloughDrive extends RobotDriveBase implements Sendable, AutoClose
SendableRegistry.remove(this);
}
/**
* Verifies that all motors are nonnull, throwing a NullPointerException if any of them are. The
* exception's error message will specify all null motors, e.g. {@code
* NullPointerException("leftMotor, rightMotor")}, to give as much information as possible to the
* programmer.
*
* @throws NullPointerException if any of the given motors are null
*/
@SuppressWarnings("PMD.AvoidThrowingNullPointerException")
private void verify(
SpeedController leftMotor, SpeedController rightMotor, SpeedController backMotor) {
if (leftMotor != null && rightMotor != null && backMotor != null) {
return;
}
StringJoiner joiner = new StringJoiner(", ");
if (leftMotor == null) {
joiner.add("leftMotor");
}
if (rightMotor == null) {
joiner.add("rightMotor");
}
if (backMotor == null) {
joiner.add("backMotor");
}
throw new NullPointerException(joiner.toString());
}
/**
* Drive method for Killough platform.
*

View File

@@ -4,6 +4,8 @@
package edu.wpi.first.wpilibj.drive;
import static java.util.Objects.requireNonNull;
import edu.wpi.first.hal.FRCNetComm.tInstances;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
@@ -12,7 +14,6 @@ import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
import java.util.StringJoiner;
/**
* A class for driving Mecanum drive platforms.
@@ -104,7 +105,11 @@ public class MecanumDrive extends RobotDriveBase implements Sendable, AutoClosea
SpeedController rearLeftMotor,
SpeedController frontRightMotor,
SpeedController rearRightMotor) {
verify(frontLeftMotor, rearLeftMotor, frontRightMotor, rearRightMotor);
requireNonNull(frontLeftMotor, "Front-left motor cannot be null");
requireNonNull(rearLeftMotor, "Rear-left motor cannot be null");
requireNonNull(frontRightMotor, "Front-right motor cannot be null");
requireNonNull(rearRightMotor, "Rear-right motor cannot be null");
m_frontLeftMotor = frontLeftMotor;
m_rearLeftMotor = rearLeftMotor;
m_frontRightMotor = frontRightMotor;
@@ -122,39 +127,6 @@ public class MecanumDrive extends RobotDriveBase implements Sendable, AutoClosea
SendableRegistry.remove(this);
}
/**
* Verifies that all motors are nonnull, throwing a NullPointerException if any of them are. The
* exception's error message will specify all null motors, e.g. {@code
* NullPointerException("frontLeftMotor, rearRightMotor")}, to give as much information as
* possible to the programmer.
*
* @throws NullPointerException if any of the given motors are null
*/
@SuppressWarnings({"PMD.AvoidThrowingNullPointerException", "PMD.CyclomaticComplexity"})
private void verify(
SpeedController frontLeft,
SpeedController rearLeft,
SpeedController frontRight,
SpeedController rearRightMotor) {
if (frontLeft != null && rearLeft != null && frontRight != null && rearRightMotor != null) {
return;
}
StringJoiner joiner = new StringJoiner(", ");
if (frontLeft == null) {
joiner.add("frontLeftMotor");
}
if (rearLeft == null) {
joiner.add("rearLeftMotor");
}
if (frontRight == null) {
joiner.add("frontRightMotor");
}
if (rearRightMotor == null) {
joiner.add("rearRightMotor");
}
throw new NullPointerException(joiner.toString());
}
/**
* Drive method for Mecanum platform.
*

View File

@@ -128,7 +128,6 @@ public class LiveWindow {
* <p>Actuators are handled through callbacks on their value changing from the SmartDashboard
* widgets.
*/
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
public static synchronized void updateValues() {
// Only do this if either LiveWindow mode or telemetry is enabled.
if (!liveWindowEnabled && !telemetryEnabled) {

View File

@@ -20,14 +20,11 @@ public class MotorControllerGroup implements MotorController, Sendable, AutoClos
*
* @param motorControllers The MotorControllers to add
*/
@SuppressWarnings("PMD.AvoidArrayLoops")
public MotorControllerGroup(
MotorController motorController, MotorController... motorControllers) {
m_motorControllers = new MotorController[motorControllers.length + 1];
m_motorControllers[0] = motorController;
for (int i = 0; i < motorControllers.length; i++) {
m_motorControllers[i + 1] = motorControllers[i];
}
System.arraycopy(motorControllers, 0, m_motorControllers, 1, motorControllers.length);
init();
}

View File

@@ -10,7 +10,6 @@ import edu.wpi.first.hal.simulation.NotifyCallback;
import edu.wpi.first.wpilibj.DriverStation;
/** Class to control a simulated driver station. */
@SuppressWarnings({"PMD.UseUtilityClass", "PMD.GodClass", "PMD.ExcessivePublicCount"})
public final class DriverStationSim {
private DriverStationSim() {
throw new UnsupportedOperationException("This is a utility class!");

View File

@@ -7,9 +7,12 @@ package edu.wpi.first.wpilibj.simulation;
import edu.wpi.first.hal.simulation.NotifyCallback;
import edu.wpi.first.hal.simulation.RoboRioDataJNI;
/** Class to control a simulated RoboRIO. */
@SuppressWarnings({"PMD.ExcessivePublicCount", "PMD.UseUtilityClass"})
public class RoboRioSim {
/** A utility class to control a simulated RoboRIO. */
public final class RoboRioSim {
private RoboRioSim() {
// Utility class
}
/**
* Register a callback to be run when the FPGA button state changes.
*

View File

@@ -153,7 +153,6 @@ public class FieldObject2d {
}
}
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
private synchronized void updateFromEntry() {
if (m_entry == null) {
return;

View File

@@ -441,11 +441,7 @@ public class SendableRegistry {
* @param dataHandle data handle to get data object passed to callback
* @param callback function to call for each object
*/
@SuppressWarnings({
"PMD.CyclomaticComplexity",
"PMD.AvoidInstantiatingObjectsInLoops",
"PMD.AvoidCatchingThrowable"
})
@SuppressWarnings("PMD.AvoidCatchingThrowable")
public static synchronized void foreachLiveWindow(
int dataHandle, Consumer<CallbackData> callback) {
CallbackData cbdata = new CallbackData();

View File

@@ -22,7 +22,6 @@ import java.util.Set;
* <p>When a value is put into the SmartDashboard here, it pops up on the SmartDashboard on the
* laptop. Users can put values into and get values from the SmartDashboard.
*/
@SuppressWarnings("PMD.GodClass")
public final class SmartDashboard {
/** The {@link NetworkTable} used by {@link SmartDashboard}. */
private static final NetworkTable table =