mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
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:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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().");
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user