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

@@ -179,7 +179,7 @@ public class CameraServerJNI {
kSourceFramesReceived(2);
@SuppressWarnings("MemberName")
private int value;
private final int value;
TelemetryKind(int value) {
this.value = value;

View File

@@ -15,7 +15,7 @@ public class HttpCamera extends VideoCamera {
kUnknown(0), kMJPGStreamer(1), kCSCore(2), kAxis(3);
@SuppressWarnings("MemberName")
private int value;
private final int value;
HttpCameraKind(int value) {
this.value = value;

View File

@@ -11,7 +11,7 @@ package edu.wpi.cscore;
* A source that represents a video camera.
*/
public class VideoCamera extends VideoSource {
public class WhiteBalance {
public static class WhiteBalance {
public static final int kFixedIndoor = 3000;
public static final int kFixedOutdoor1 = 4000;
public static final int kFixedOutdoor2 = 5000;

View File

@@ -34,7 +34,7 @@ public class VideoEvent {
kSinkPropertyChoicesUpdated(0x40000);
@SuppressWarnings("MemberName")
private int value;
private final int value;
Kind(int value) {
this.value = value;

View File

@@ -15,7 +15,7 @@ public class VideoMode {
kUnknown(0), kMJPEG(1), kYUYV(2), kRGB565(3), kBGR(4), kGray(5);
@SuppressWarnings("MemberName")
private int value;
private final int value;
PixelFormat(int value) {
this.value = value;

View File

@@ -15,7 +15,7 @@ public class VideoProperty {
kNone(0), kBoolean(1), kInteger(2), kString(4), kEnum(8);
@SuppressWarnings("MemberName")
private int value;
private final int value;
Kind(int value) {
this.value = value;

View File

@@ -17,7 +17,7 @@ public class VideoSink implements AutoCloseable {
kUnknown(0), kMjpeg(2), kCv(4);
@SuppressWarnings("MemberName")
private int value;
private final int value;
Kind(int value) {
this.value = value;

View File

@@ -25,7 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
class UsbCameraTest {
@Nested
@EnabledOnOs(OS.LINUX)
class ConnectVerbose {
static class ConnectVerbose {
@Test
void setConnectVerboseEnabledTest() {
try (UsbCamera camera = new UsbCamera("Nonexistant Camera", getNonexistentCameraDev())) {

View File

@@ -54,7 +54,7 @@ public class PDPSim {
return new CallbackStore(m_index, channel, uid, PDPDataJNI::cancelCurrentCallback);
}
public double getCurrent(int channel) {
return PDPDataJNI.getCurrent(channel, m_index);
return PDPDataJNI.getCurrent(m_index, channel);
}
public void setCurrent(int channel, double current) {
PDPDataJNI.setCurrent(m_index, channel, current);

View File

@@ -258,7 +258,7 @@ public final class NetworkTableValue {
* @return The entry value
*/
public static NetworkTableValue makeBoolean(boolean value) {
return new NetworkTableValue(NetworkTableType.kBoolean, new Boolean(value));
return new NetworkTableValue(NetworkTableType.kBoolean, Boolean.valueOf(value));
}
/**
@@ -269,7 +269,7 @@ public final class NetworkTableValue {
* @return The entry value
*/
public static NetworkTableValue makeBoolean(boolean value, long time) {
return new NetworkTableValue(NetworkTableType.kBoolean, new Boolean(value), time);
return new NetworkTableValue(NetworkTableType.kBoolean, Boolean.valueOf(value), time);
}
/**
@@ -279,7 +279,7 @@ public final class NetworkTableValue {
* @return The entry value
*/
public static NetworkTableValue makeDouble(double value) {
return new NetworkTableValue(NetworkTableType.kDouble, new Double(value));
return new NetworkTableValue(NetworkTableType.kDouble, Double.valueOf(value));
}
/**
@@ -290,7 +290,7 @@ public final class NetworkTableValue {
* @return The entry value
*/
public static NetworkTableValue makeDouble(double value, long time) {
return new NetworkTableValue(NetworkTableType.kDouble, new Double(value), time);
return new NetworkTableValue(NetworkTableType.kDouble, Double.valueOf(value), time);
}
/**

View File

@@ -483,7 +483,7 @@ public class NetworkTable implements ITable, IRemote {
public int uid;
}
private class OldTableListenerAdapter extends ListenerBase implements Consumer<EntryNotification> {
private static class OldTableListenerAdapter extends ListenerBase implements Consumer<EntryNotification> {
private final int prefixLen;
private final ITable targetSource;
private final ITableListener targetListener;
@@ -539,7 +539,7 @@ public class NetworkTable implements ITable, IRemote {
addTableListenerEx(key, listener, flags);
}
private class OldKeyListenerAdapter extends ListenerBase implements Consumer<EntryNotification> {
private static class OldKeyListenerAdapter extends ListenerBase implements Consumer<EntryNotification> {
private final String relativeKey;
private final ITable targetSource;
private final ITableListener targetListener;
@@ -587,7 +587,7 @@ public class NetworkTable implements ITable, IRemote {
addSubTableListener(listener, false);
}
private class OldSubListenerAdapter extends ListenerBase implements Consumer<EntryNotification> {
private static class OldSubListenerAdapter extends ListenerBase implements Consumer<EntryNotification> {
private final int prefixLen;
private final ITable targetSource;
private final ITableListener targetListener;

View File

@@ -52,9 +52,6 @@ class TimedRobot : public IterativeRobotBase, public ErrorBase {
// The absolute expiration time
double m_expirationTime = 0;
// The relative time
double m_period;
/**
* Update the HAL alarm time.
*/

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();

View File

@@ -11,6 +11,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.DigestInputStream;
@@ -67,7 +68,7 @@ public final class RuntimeLoader<T> {
if (hashIs == null) {
throw new IOException(hashName + " Resource not found");
}
try (Scanner scanner = new Scanner(hashIs)) {
try (Scanner scanner = new Scanner(hashIs, StandardCharsets.UTF_8.name())) {
String hash = scanner.nextLine();
File jniLibrary = new File(m_extractionRoot, resname + "." + hash);
try {