[build] Enable spotbugs (#3601)

Benign spotbugs warnings were suppressed, and all others were fixed. Bug
descriptions are documented here:
https://spotbugs.readthedocs.io/en/stable/bugDescriptions.html

Co-authored-by: Austin Shalit <austinshalit@gmail.com>
This commit is contained in:
Tyler Veness
2021-09-24 16:04:02 -07:00
committed by GitHub
parent b65fce86bf
commit 95dd20a151
73 changed files with 356 additions and 558 deletions

View File

@@ -183,6 +183,6 @@ public class PIDTest extends AbstractComsSetup {
@Test(expected = RuntimeException.class)
public void testOnTargetNoToleranceSet() {
setupIntegratorRange();
m_controller.atSetpoint();
assertFalse(m_controller.atSetpoint());
}
}

View File

@@ -12,7 +12,7 @@ public class CANStatusTest {
@Test
public void canStatusGetDoesntThrow() {
CANStatus status = new CANStatus();
CANJNI.GetCANStatus(status);
CANJNI.getCANStatus(status);
// Nothing we can assert, so just make sure it didn't throw.
}
}

View File

@@ -34,10 +34,9 @@ public abstract class AnalogCrossConnectFixture implements ITestFixture {
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#setup()
*/
@Override
public boolean setup() {
public void setup() {
initialize();
m_output.setVoltage(0);
return true;
}
/*
@@ -46,9 +45,8 @@ public abstract class AnalogCrossConnectFixture implements ITestFixture {
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#reset()
*/
@Override
public boolean reset() {
public void reset() {
initialize();
return true;
}
/*
@@ -57,10 +55,9 @@ public abstract class AnalogCrossConnectFixture implements ITestFixture {
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#teardown()
*/
@Override
public boolean teardown() {
public void teardown() {
m_input.close();
m_output.close();
return true;
}
/** Analog Output. */

View File

@@ -55,24 +55,20 @@ public class DIOCrossConnectFixture implements ITestFixture {
}
@Override
public boolean setup() {
return true;
}
public void setup() {}
@Override
public boolean reset() {
public void reset() {
m_output.set(false);
return true;
}
@Override
public boolean teardown() {
public void teardown() {
logger.log(Level.FINE, "Beginning teardown");
if (m_allocated) {
m_input.close();
m_output.close();
m_allocated = false;
}
return true;
}
}

View File

@@ -67,9 +67,7 @@ public class FakeCounterFixture implements ITestFixture {
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#setup()
*/
@Override
public boolean setup() {
return true;
}
public void setup() {}
/*
* (non-Javadoc)
@@ -77,9 +75,8 @@ public class FakeCounterFixture implements ITestFixture {
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#reset()
*/
@Override
public boolean reset() {
public void reset() {
m_counter.reset();
return true;
}
/*
@@ -88,7 +85,7 @@ public class FakeCounterFixture implements ITestFixture {
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#teardown()
*/
@Override
public boolean teardown() {
public void teardown() {
logger.log(Level.FINE, "Beginning teardown");
m_counter.close();
m_source.close();
@@ -96,6 +93,5 @@ public class FakeCounterFixture implements ITestFixture {
m_dio.teardown();
m_allocated = false;
}
return true;
}
}

View File

@@ -68,9 +68,7 @@ public class FakeEncoderFixture implements ITestFixture {
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#setup()
*/
@Override
public boolean setup() {
return true;
}
public void setup() {}
/*
* (non-Javadoc)
@@ -78,11 +76,10 @@ public class FakeEncoderFixture implements ITestFixture {
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#reset()
*/
@Override
public boolean reset() {
public void reset() {
m_dio1.reset();
m_dio2.reset();
m_encoder.reset();
return true;
}
/*
@@ -91,7 +88,7 @@ public class FakeEncoderFixture implements ITestFixture {
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#teardown()
*/
@Override
public boolean teardown() {
public void teardown() {
logger.fine("Beginning teardown");
m_source.close();
logger.finer("Source freed " + m_sourcePort[0] + ", " + m_sourcePort[1]);
@@ -101,6 +98,5 @@ public class FakeEncoderFixture implements ITestFixture {
m_dio1.teardown();
m_dio2.teardown();
}
return true;
}
}

View File

@@ -18,10 +18,8 @@ public interface ITestFixture {
/**
* Performs any required setup for this fixture, ensuring that all fixture elements are ready for
* testing.
*
* @return True if the fixture is ready for testing
*/
boolean setup();
void setup();
/**
* Resets the fixture back to test start state. This should be called by the test class in the
@@ -29,16 +27,12 @@ public interface ITestFixture {
* ITestFixture#setup()} as that is called once, before the class is constructed, so it may need
* to start sensors. This method should not have to start anything, just reset sensors and ensure
* that motors are stopped.
*
* @return True if the fixture is ready for testing
*/
boolean reset();
void reset();
/**
* Performs any required teardown after use of the fixture, ensuring that future tests will not
* run into conflicts.
*
* @return True if the teardown succeeded
*/
boolean teardown();
void teardown();
}

View File

@@ -82,9 +82,8 @@ public abstract class MotorEncoderFixture<T extends MotorController> implements
}
@Override
public boolean setup() {
public void setup() {
initialize();
return true;
}
/**
@@ -136,7 +135,7 @@ public abstract class MotorEncoderFixture<T extends MotorController> implements
}
@Override
public boolean reset() {
public void reset() {
initialize();
m_motor.setInverted(false);
m_motor.set(0);
@@ -145,15 +144,6 @@ public abstract class MotorEncoderFixture<T extends MotorController> implements
for (Counter c : m_counters) {
c.reset();
}
boolean wasReset = true;
wasReset = wasReset && m_motor.get() == 0;
wasReset = wasReset && m_encoder.get() == 0;
for (Counter c : m_counters) {
wasReset = wasReset && c.get() == 0;
}
return wasReset;
}
/**
@@ -163,62 +153,37 @@ public abstract class MotorEncoderFixture<T extends MotorController> implements
*/
@Override
@SuppressWarnings("Regexp")
public boolean teardown() {
String type;
if (m_motor != null) {
type = getType();
} else {
type = "null";
}
public void teardown() {
if (!m_tornDown) {
boolean wasNull = false;
if (m_motor instanceof PWM && m_motor != null) {
((PWM) m_motor).close();
if (m_motor != null) {
if (m_motor instanceof PWM) {
((PWM) m_motor).close();
}
m_motor = null;
} else if (m_motor == null) {
wasNull = true;
}
if (m_encoder != null) {
m_encoder.close();
m_encoder = null;
} else {
wasNull = true;
}
if (m_counters[0] != null) {
m_counters[0].close();
m_counters[0] = null;
} else {
wasNull = true;
}
if (m_counters[1] != null) {
m_counters[1].close();
m_counters[1] = null;
} else {
wasNull = true;
}
if (m_alphaSource != null) {
m_alphaSource.close();
m_alphaSource = null;
} else {
wasNull = true;
}
if (m_betaSource != null) {
m_betaSource.close();
m_betaSource = null;
} else {
wasNull = true;
}
m_tornDown = true;
if (wasNull) {
throw new NullPointerException("MotorEncoderFixture had null params at teardown");
}
} else {
throw new RuntimeException(type + " Motor Encoder torn down multiple times");
}
return true;
}
@Override

View File

@@ -54,9 +54,8 @@ public abstract class RelayCrossConnectFixture implements ITestFixture {
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#setup()
*/
@Override
public boolean setup() {
public void setup() {
initialize();
return true;
}
/*
@@ -65,9 +64,8 @@ public abstract class RelayCrossConnectFixture implements ITestFixture {
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#reset()
*/
@Override
public boolean reset() {
public void reset() {
initialize();
return true;
}
/*
@@ -76,7 +74,7 @@ public abstract class RelayCrossConnectFixture implements ITestFixture {
* @see edu.wpi.first.wpilibj.fixtures.ITestFixture#teardown()
*/
@Override
public boolean teardown() {
public void teardown() {
if (!m_freed) {
m_relay.close();
m_inputOne.close();
@@ -88,6 +86,5 @@ public abstract class RelayCrossConnectFixture implements ITestFixture {
+ RelayCrossConnectFixture.class.getSimpleName()
+ " multiple times");
}
return true;
}
}

View File

@@ -10,35 +10,32 @@ package edu.wpi.first.wpilibj.fixtures;
*/
public class SampleFixture implements ITestFixture {
@Override
public boolean setup() {
public void setup() {
/*
* If this fixture actually accessed the hardware, here is where it would
* set up the starting state of the test bench. For example, reseting
* encoders, ensuring motors are stopped, reseting any serial communication
* if necessary, etc.
*/
return true;
}
@Override
public boolean reset() {
public void reset() {
/*
* This is where the fixture would reset any sensors or motors used by the
* fixture to test default state. This method should not worry about whether
* or not the sensors have been allocated correctly, that is the job of the
* setup function.
*/
return false;
}
@Override
public boolean teardown() {
public void teardown() {
/*
* This is where the fixture would deallocate and reset back to normal
* conditions any necessary hardware. This includes ensuring motors are
* stopped, stoppable sensors are actually stopped, ensuring serial
* communications are ready for the next test, etc.
*/
return true;
}
}

View File

@@ -35,8 +35,7 @@ public abstract class TiltPanCameraFixture implements ITestFixture {
public TiltPanCameraFixture() {}
@Override
public boolean setup() {
boolean wasSetup = false;
public void setup() {
if (!m_initialized) {
m_initialized = true;
m_tilt = giveTilt();
@@ -48,17 +47,14 @@ public abstract class TiltPanCameraFixture implements ITestFixture {
logger.fine("Initializing the gyro");
m_gyro = giveGyro();
m_gyro.reset();
wasSetup = true;
}
return wasSetup;
}
@Override
public boolean reset() {
public void reset() {
if (m_gyro != null) {
m_gyro.reset();
}
return true;
}
public Servo getTilt() {
@@ -89,7 +85,7 @@ public abstract class TiltPanCameraFixture implements ITestFixture {
}
@Override
public boolean teardown() {
public void teardown() {
m_tilt.close();
m_tilt = null;
m_pan.close();
@@ -102,6 +98,5 @@ public abstract class TiltPanCameraFixture implements ITestFixture {
m_gyroParam.close();
m_gyroParam = null;
}
return true;
}
}

View File

@@ -16,7 +16,7 @@ public class FakeCounterSource implements AutoCloseable {
private boolean m_allocated;
/** Thread object that allows emulation of an encoder. */
private class EncoderThread extends Thread {
private static class EncoderThread extends Thread {
FakeCounterSource m_encoder;
EncoderThread(FakeCounterSource encode) {

View File

@@ -18,7 +18,7 @@ public class FakeEncoderSource implements AutoCloseable {
private final boolean m_allocatedOutputs;
/** Thread object that allows emulation of a quadrature encoder. */
private class QuadEncoderThread extends Thread {
private static class QuadEncoderThread extends Thread {
FakeEncoderSource m_encoder;
QuadEncoderThread(FakeEncoderSource encode) {

View File

@@ -201,7 +201,7 @@ public abstract class AbstractComsSetup {
* Provided as a replacement to lambda functions to allow for repeatable checks to see if a
* correct state is reached.
*/
public abstract class BooleanCheck {
public abstract static class BooleanCheck {
public BooleanCheck() {}
/**

View File

@@ -59,7 +59,7 @@ public abstract class AbstractTestSuite {
* Stores a method name and method class pair. Used when searching for methods matching a given
* regex text.
*/
protected class ClassMethodPair {
protected static class ClassMethodPair {
public final Class<?> m_methodClass;
public final String m_methodName;

View File

@@ -35,7 +35,7 @@ public class AbstractTestSuiteTest {
ExampleSubSuite.class,
EmptySuite.class
})
class TestForAbstractTestSuite extends AbstractTestSuite {}
static class TestForAbstractTestSuite extends AbstractTestSuite {}
TestForAbstractTestSuite m_testSuite;

View File

@@ -16,7 +16,7 @@ import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest;
* Provides an entry point for tests to run with ANT. This allows ant to output JUnit XML test
* results for Jenkins.
*/
public class AntJunitLanucher {
public class AntJunitLauncher {
/**
* Main entry point for jenkins.
*

View File

@@ -42,6 +42,11 @@ public class TestSuite extends AbstractTestSuite {
Logger.getAnonymousLogger().severe("Could not load default logging.properties file");
Logger.getAnonymousLogger().severe(ex.getMessage());
}
try {
inputStream.close();
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
TestBench.out().println("Starting Tests");
}
@@ -172,11 +177,11 @@ public class TestSuite extends AbstractTestSuite {
for (String s : args) {
if (Pattern.matches(METHOD_NAME_FILTER + ".*", s)) {
methodFilter = true;
methodRegex = new String(s).replace(METHOD_NAME_FILTER, "");
methodRegex = s.replace(METHOD_NAME_FILTER, "");
}
if (Pattern.matches(METHOD_REPEAT_FILTER + ".*", s)) {
try {
repeatCount = Integer.parseInt(new String(s).replace(METHOD_REPEAT_FILTER, ""));
repeatCount = Integer.parseInt(s.replace(METHOD_REPEAT_FILTER, ""));
} catch (NumberFormatException ex) {
displayInvalidUsage(
"The argument passed to the repeat rule was not a valid integer.", args);