Fix many errorprone warnings (#1247)

This fixes two real bugs:
- TimedRobot had a m_period that was hiding the IterativeRobotBase m_period
  and was not getting initialized.
- PDPSim was swapping two parameters to getCurrent()
This commit is contained in:
Peter Johnson
2018-07-29 16:47:22 -07:00
committed by GitHub
parent 6db5f80430
commit 0e9172f9a7
28 changed files with 50 additions and 43 deletions

View File

@@ -24,7 +24,7 @@ public class AnalogTrigger extends SendableBase {
/**
* Exceptions dealing with improper operation of the Analog trigger.
*/
public class AnalogTriggerException extends RuntimeException {
public static class AnalogTriggerException extends RuntimeException {
/**
* Create a new exception with the given message.
*

View File

@@ -44,7 +44,7 @@ public class AnalogTriggerOutput extends DigitalSource {
/**
* Exceptions dealing with improper operation of the Analog trigger output.
*/
public class AnalogTriggerOutputException extends RuntimeException {
public static class AnalogTriggerOutputException extends RuntimeException {
/**
* Create a new exception with the given message.
*

View File

@@ -34,12 +34,12 @@ public class DriverStation {
*/
public static final int kJoystickPorts = 6;
private class HALJoystickButtons {
private static class HALJoystickButtons {
public int m_buttons;
public byte m_count;
}
private class HALJoystickAxes {
private static class HALJoystickAxes {
public float[] m_axes;
public short m_count;
@@ -48,7 +48,7 @@ public class DriverStation {
}
}
private class HALJoystickPOVs {
private static class HALJoystickPOVs {
public short[] m_povs;
public short m_count;

View File

@@ -100,7 +100,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")
@SuppressWarnings({"PMD.CyclomaticComplexity", "ByteBufferBackingArray"})
public synchronized boolean transaction(ByteBuffer dataToSend, int sendSize,
ByteBuffer dataReceived, int receiveSize) {
if (dataToSend.hasArray() && dataReceived.hasArray()) {
@@ -191,6 +191,7 @@ public class I2C implements AutoCloseable {
* @param size The number of data bytes to write.
* @return Transfer Aborted... false for success, true for aborted.
*/
@SuppressWarnings("ByteBufferBackingArray")
public synchronized boolean writeBulk(ByteBuffer data, int size) {
if (data.hasArray()) {
return writeBulk(data.array(), size);
@@ -246,6 +247,7 @@ public class I2C implements AutoCloseable {
* @param buffer A buffer to store the data read from the device.
* @return Transfer Aborted... false for success, true for aborted.
*/
@SuppressWarnings("ByteBufferBackingArray")
public boolean read(int registerAddress, int count, ByteBuffer buffer) {
if (count < 1) {
throw new BoundaryException("Value must be at least 1, " + count + " given");
@@ -303,6 +305,7 @@ public class I2C implements AutoCloseable {
* @param count The number of bytes to read in the transaction.
* @return Transfer Aborted... false for success, true for aborted.
*/
@SuppressWarnings("ByteBufferBackingArray")
public boolean readOnly(ByteBuffer buffer, int count) {
if (count < 1) {
throw new BoundaryException("Value must be at least 1, " + count

View File

@@ -110,7 +110,7 @@ public class PIDBase extends SendableBase implements PIDInterface, PIDOutput {
/**
* Used internally for when Tolerance hasn't been set.
*/
public class NullTolerance implements Tolerance {
public static class NullTolerance implements Tolerance {
@Override
public boolean onTarget() {
throw new IllegalStateException("No tolerance value set when calling onTarget().");

View File

@@ -34,7 +34,7 @@ public class Relay extends SendableBase implements MotorSafety {
* This class represents errors in trying to set relay values contradictory to the direction to
* which the relay is set.
*/
public class InvalidValueException extends RuntimeException {
public static class InvalidValueException extends RuntimeException {
/**
* Create a new exception with the given message.
*

View File

@@ -10,6 +10,7 @@ package edu.wpi.first.wpilibj;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.function.Supplier;
@@ -242,12 +243,13 @@ public abstract class RobotBase implements AutoCloseable {
file.createNewFile();
try (OutputStream output = Files.newOutputStream(file.toPath())) {
output.write("Java ".getBytes());
output.write(WPILibVersion.Version.getBytes());
output.write("Java ".getBytes(StandardCharsets.UTF_8));
output.write(WPILibVersion.Version.getBytes(StandardCharsets.UTF_8));
}
} catch (IOException ex) {
ex.printStackTrace();
DriverStation.reportError("Could not write FRC_Lib_Version.ini: " + ex.toString(),
ex.getStackTrace());
}
boolean errorOnExit = false;

View File

@@ -22,7 +22,7 @@ public class SPI implements AutoCloseable {
kOnboardCS0(0), kOnboardCS1(1), kOnboardCS2(2), kOnboardCS3(3), kMXP(4);
@SuppressWarnings("MemberName")
public int value;
public final int value;
Port(int value) {
this.value = value;
@@ -188,6 +188,7 @@ public class SPI implements AutoCloseable {
*
* @param dataToSend The buffer containing the data to send.
*/
@SuppressWarnings("ByteBufferBackingArray")
public int write(ByteBuffer dataToSend, int size) {
if (dataToSend.hasArray()) {
return write(dataToSend.array(), size);
@@ -232,6 +233,7 @@ public class SPI implements AutoCloseable {
* @param dataReceived The buffer to be filled with the received data.
* @param size The length of the transaction, in bytes
*/
@SuppressWarnings("ByteBufferBackingArray")
public int read(boolean initiate, ByteBuffer dataReceived, int size) {
if (dataReceived.hasArray()) {
return read(initiate, dataReceived.array(), size);
@@ -269,7 +271,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")
@SuppressWarnings({"PMD.CyclomaticComplexity", "ByteBufferBackingArray"})
public int transaction(ByteBuffer dataToSend, ByteBuffer dataReceived, int size) {
if (dataToSend.hasArray() && dataReceived.hasArray()) {
return transaction(dataToSend.array(), dataReceived.array(), size);
@@ -376,6 +378,7 @@ public class SPI implements AutoCloseable {
* @param timeout timeout in seconds (ms resolution)
* @return Number of bytes remaining to be read
*/
@SuppressWarnings("ByteBufferBackingArray")
public int readAutoReceivedData(ByteBuffer buffer, int numToRead, double timeout) {
if (buffer.hasArray()) {
return readAutoReceivedData(buffer.array(), numToRead, timeout);

View File

@@ -8,6 +8,7 @@
package edu.wpi.first.wpilibj;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType;
import edu.wpi.first.wpilibj.hal.HAL;
@@ -32,7 +33,7 @@ public class SerialPort implements AutoCloseable {
kOnboard(0), kMXP(1), kUSB(2), kUSB1(2), kUSB2(3);
@SuppressWarnings("MemberName")
public int value;
public final int value;
Port(int value) {
this.value = value;
@@ -316,7 +317,7 @@ public class SerialPort implements AutoCloseable {
* @return The number of bytes actually written into the port.
*/
public int writeString(String data) {
return write(data.getBytes(), data.length());
return write(data.getBytes(StandardCharsets.UTF_8), data.length());
}
/**

View File

@@ -29,8 +29,6 @@ public class TimedRobot extends IterativeRobotBase {
// The absolute expiration time
private double m_expirationTime;
private double m_period;
/**
* Constructor for TimedRobot.
*/
@@ -60,6 +58,7 @@ public class TimedRobot extends IterativeRobotBase {
* Provide an alternate "main loop" via startCompetition().
*/
@Override
@SuppressWarnings("UnsafeFinalization")
public void startCompetition() {
robotInit();
@@ -93,6 +92,7 @@ public class TimedRobot extends IterativeRobotBase {
/**
* Update the alarm hardware to reflect the next alarm.
*/
@SuppressWarnings("UnsafeFinalization")
private void updateAlarm() {
NotifierJNI.updateNotifierAlarm(m_notifier, (long) (m_expirationTime * 1e6));
}

View File

@@ -65,7 +65,7 @@ public class Ultrasonic extends SendableBase implements PIDSource {
* certainly break. Make sure to disable automatic mode before changing anything with the
* sensors!!
*/
private class UltrasonicChecker extends Thread {
private static class UltrasonicChecker extends Thread {
@Override
public synchronized void run() {
Ultrasonic ultrasonic = null;

View File

@@ -34,7 +34,7 @@ public class XboxController extends GenericHID {
kStart(8);
@SuppressWarnings({"MemberName", "PMD.SingularField"})
private int value;
private final int value;
Button(int value) {
this.value = value;

View File

@@ -172,7 +172,7 @@ public abstract class Trigger extends SendableBase {
* An internal class of {@link Trigger}. The user should ignore this, it is only public to
* interface between packages.
*/
public abstract class ButtonScheduler {
public abstract static class ButtonScheduler {
public abstract void execute();
protected void start() {

View File

@@ -147,7 +147,7 @@ public abstract class ConditionalCommand extends Command {
}
@Override
protected void _cancel() {
protected synchronized void _cancel() {
if (m_chosenCommand != null && m_chosenCommand.isRunning()) {
m_chosenCommand.cancel();
}

View File

@@ -48,7 +48,7 @@ public class SortedVector<E> extends Vector<E> {
* @param element The element to add to the Vector
*/
@Override
public void addElement(E element) {
public synchronized void addElement(E element) {
int highBound = size();
int lowBound = 0;
while (highBound - lowBound > 0) {
@@ -70,7 +70,7 @@ public class SortedVector<E> extends Vector<E> {
* Sort the vector.
*/
@SuppressWarnings("unchecked")
public void sort() {
public synchronized void sort() {
Object[] array = new Object[size()];
copyInto(array);
removeAllElements();