mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[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:
@@ -21,7 +21,8 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
public class DigitalGlitchFilter implements Sendable, AutoCloseable {
|
||||
/** Configures the Digital Glitch Filter to its default settings. */
|
||||
public DigitalGlitchFilter() {
|
||||
synchronized (m_mutex) {
|
||||
m_mutex.lock();
|
||||
try {
|
||||
int index = 0;
|
||||
while (m_filterAllocated[index] && index < m_filterAllocated.length) {
|
||||
index++;
|
||||
@@ -32,6 +33,8 @@ public class DigitalGlitchFilter implements Sendable, AutoCloseable {
|
||||
HAL.report(tResourceType.kResourceType_DigitalGlitchFilter, m_channelIndex + 1, 0);
|
||||
SendableRegistry.addLW(this, "DigitalGlitchFilter", index);
|
||||
}
|
||||
} finally {
|
||||
m_mutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,9 +42,13 @@ public class DigitalGlitchFilter implements Sendable, AutoCloseable {
|
||||
public void close() {
|
||||
SendableRegistry.remove(this);
|
||||
if (m_channelIndex >= 0) {
|
||||
synchronized (m_mutex) {
|
||||
m_mutex.lock();
|
||||
try {
|
||||
m_filterAllocated[m_channelIndex] = false;
|
||||
} finally {
|
||||
m_mutex.unlock();
|
||||
}
|
||||
|
||||
m_channelIndex = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,12 +188,15 @@ public class DriverStation {
|
||||
int currentReplayNumber;
|
||||
int currentMatchType;
|
||||
int currentControlWord;
|
||||
synchronized (DriverStation.m_cacheDataMutex) {
|
||||
m_cacheDataMutex.lock();
|
||||
try {
|
||||
currentEventName = DriverStation.m_matchInfo.eventName;
|
||||
currentGameSpecificMessage = DriverStation.m_matchInfo.gameSpecificMessage;
|
||||
currentMatchNumber = DriverStation.m_matchInfo.matchNumber;
|
||||
currentReplayNumber = DriverStation.m_matchInfo.replayNumber;
|
||||
currentMatchType = DriverStation.m_matchInfo.matchType;
|
||||
} finally {
|
||||
m_cacheDataMutex.unlock();
|
||||
}
|
||||
currentControlWord = HAL.nativeGetControlWord();
|
||||
|
||||
@@ -1178,9 +1181,12 @@ public class DriverStation {
|
||||
/** Forces waitForData() to return immediately. */
|
||||
public static void wakeupWaitForData() {
|
||||
m_waitForDataMutex.lock();
|
||||
m_waitForDataCount++;
|
||||
m_waitForDataCond.signalAll();
|
||||
m_waitForDataMutex.unlock();
|
||||
try {
|
||||
m_waitForDataCount++;
|
||||
m_waitForDataCond.signalAll();
|
||||
} finally {
|
||||
m_waitForDataMutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -348,20 +348,20 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
m_runMutex.unlock();
|
||||
|
||||
if (isReal()) {
|
||||
final File file = new File("/tmp/frc_versions/FRC_Lib_Version.ini");
|
||||
try {
|
||||
final File file = new File("/tmp/frc_versions/FRC_Lib_Version.ini");
|
||||
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
if (file.exists() && !file.delete()) {
|
||||
throw new IOException("Failed to delete FRC_Lib_Version.ini");
|
||||
}
|
||||
|
||||
file.createNewFile();
|
||||
if (!file.createNewFile()) {
|
||||
throw new IOException("Failed to create new FRC_Lib_Version.ini");
|
||||
}
|
||||
|
||||
try (OutputStream output = Files.newOutputStream(file.toPath())) {
|
||||
output.write("Java ".getBytes(StandardCharsets.UTF_8));
|
||||
output.write(WPILibVersion.Version.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
} catch (IOException ex) {
|
||||
DriverStation.reportError(
|
||||
"Could not write FRC_Lib_Version.ini: " + ex.toString(), ex.getStackTrace());
|
||||
|
||||
@@ -220,7 +220,7 @@ public final class RobotController {
|
||||
*/
|
||||
public static CANStatus getCANStatus() {
|
||||
CANStatus status = new CANStatus();
|
||||
CANJNI.GetCANStatus(status);
|
||||
CANJNI.getCANStatus(status);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.PriorityQueue;
|
||||
*/
|
||||
public class TimedRobot extends IterativeRobotBase {
|
||||
@SuppressWarnings("MemberName")
|
||||
class Callback implements Comparable<Callback> {
|
||||
static class Callback implements Comparable<Callback> {
|
||||
public Runnable func;
|
||||
public double period;
|
||||
public double expirationTime;
|
||||
@@ -43,6 +43,19 @@ public class TimedRobot extends IterativeRobotBase {
|
||||
+ this.period;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object rhs) {
|
||||
if (rhs instanceof Callback) {
|
||||
return Double.compare(expirationTime, ((Callback) rhs).expirationTime) == 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Double.hashCode(expirationTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Callback rhs) {
|
||||
// Elements with sooner expiration times are sorted as lesser. The head of
|
||||
|
||||
@@ -60,20 +60,12 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
disable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Watchdog rhs) {
|
||||
// Elements with sooner expiration times are sorted as lesser. The head of
|
||||
// Java's PriorityQueue is the least element.
|
||||
return Double.compare(m_expirationTimeSeconds, rhs.m_expirationTimeSeconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof Watchdog)) {
|
||||
return false;
|
||||
if (obj instanceof Watchdog) {
|
||||
return Double.compare(m_expirationTimeSeconds, ((Watchdog) obj).m_expirationTimeSeconds) == 0;
|
||||
}
|
||||
Watchdog oth = (Watchdog) obj;
|
||||
return oth.m_expirationTimeSeconds == m_expirationTimeSeconds;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,6 +73,13 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
|
||||
return Double.hashCode(m_expirationTimeSeconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Watchdog rhs) {
|
||||
// Elements with sooner expiration times are sorted as lesser. The head of
|
||||
// Java's PriorityQueue is the least element.
|
||||
return Double.compare(m_expirationTimeSeconds, rhs.m_expirationTimeSeconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time in seconds since the watchdog was last fed.
|
||||
*
|
||||
|
||||
@@ -76,7 +76,7 @@ public class Field2d implements NTSendable {
|
||||
*/
|
||||
public synchronized FieldObject2d getObject(String name) {
|
||||
for (FieldObject2d obj : m_objects) {
|
||||
if (obj.m_name == name) {
|
||||
if (obj.m_name.equals(name)) {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -102,9 +102,9 @@ public class Field2d implements NTSendable {
|
||||
@Override
|
||||
public void initSendable(NTSendableBuilder builder) {
|
||||
builder.setSmartDashboardType("Field2d");
|
||||
m_table = builder.getTable();
|
||||
|
||||
synchronized (this) {
|
||||
m_table = builder.getTable();
|
||||
for (FieldObject2d obj : m_objects) {
|
||||
synchronized (obj) {
|
||||
obj.m_entry = m_table.getEntry(obj.m_name);
|
||||
|
||||
@@ -97,10 +97,10 @@ public final class Mechanism2d implements NTSendable {
|
||||
@Override
|
||||
public void initSendable(NTSendableBuilder builder) {
|
||||
builder.setSmartDashboardType("Mechanism2d");
|
||||
m_table = builder.getTable();
|
||||
m_table.getEntry("dims").setDoubleArray(m_dims);
|
||||
m_table.getEntry(kBackgroundColor).setString(m_color);
|
||||
synchronized (this) {
|
||||
m_table = builder.getTable();
|
||||
m_table.getEntry("dims").setDoubleArray(m_dims);
|
||||
m_table.getEntry(kBackgroundColor).setString(m_color);
|
||||
for (Entry<String, MechanismRoot2d> entry : m_roots.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
MechanismRoot2d root = entry.getValue();
|
||||
|
||||
@@ -128,7 +128,7 @@ public class MechanismLigament2d extends MechanismObject2d {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateEntries(NetworkTable table) {
|
||||
protected synchronized void updateEntries(NetworkTable table) {
|
||||
table.getEntry(".type").setString("line");
|
||||
m_angleEntry = table.getEntry("angle");
|
||||
m_lengthEntry = table.getEntry("length");
|
||||
|
||||
@@ -72,7 +72,7 @@ public final class MechanismRoot2d {
|
||||
m_y = y;
|
||||
}
|
||||
|
||||
void update(NetworkTable table) {
|
||||
synchronized void update(NetworkTable table) {
|
||||
m_table = table;
|
||||
m_xEntry = m_table.getEntry("x");
|
||||
m_yEntry = m_table.getEntry("y");
|
||||
@@ -86,7 +86,7 @@ public final class MechanismRoot2d {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
private void flush() {
|
||||
private synchronized void flush() {
|
||||
if (m_xEntry != null) {
|
||||
m_xEntry.setDouble(m_x);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user