Skip to content

Commit

Permalink
Fix trivial errorprone warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
auscompgeek committed Jan 2, 2024
1 parent c486972 commit dedf60e
Show file tree
Hide file tree
Showing 28 changed files with 45 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -234,7 +235,7 @@ public static AprilTagFieldLayout loadFromResource(String resourcePath) throws I
// Class.getResourceAsStream() returns null if the resource does not exist.
throw new IOException("Could not locate resource: " + resourcePath);
}
InputStreamReader reader = new InputStreamReader(stream);
InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8);
try {
return new ObjectMapper().readerFor(AprilTagFieldLayout.class).readValue(reader);
} catch (IOException e) {
Expand Down
5 changes: 0 additions & 5 deletions cscore/src/main/java/edu/wpi/first/cscore/VideoException.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,4 @@ public class VideoException extends RuntimeException {
public VideoException(String msg) {
super(msg);
}

@Override
public String toString() {
return "VideoException [" + super.toString() + "]";
}
}
5 changes: 1 addition & 4 deletions cscore/src/main/java/edu/wpi/first/cscore/VideoMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other == null) {
return false;
}
if (getClass() != other.getClass()) {
if (!(other instanceof VideoMode)) {
return false;
}
VideoMode mode = (VideoMode) other;
Expand Down
5 changes: 1 addition & 4 deletions cscore/src/main/java/edu/wpi/first/cscore/VideoSink.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other == null) {
return false;
}
if (getClass() != other.getClass()) {
if (!(other instanceof VideoSink)) {
return false;
}
VideoSink sink = (VideoSink) other;
Expand Down
5 changes: 1 addition & 4 deletions cscore/src/main/java/edu/wpi/first/cscore/VideoSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other == null) {
return false;
}
if (getClass() != other.getClass()) {
if (!(other instanceof VideoSource)) {
return false;
}
VideoSource source = (VideoSource) other;
Expand Down
3 changes: 2 additions & 1 deletion fieldImages/src/main/java/edu/wpi/fields/FieldConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

Expand Down Expand Up @@ -83,7 +84,7 @@ public static FieldConfig loadFromFile(Path file) throws IOException {
*/
public static FieldConfig loadFromResource(String resourcePath) throws IOException {
try (InputStream stream = FieldConfig.class.getResourceAsStream(resourcePath);
InputStreamReader reader = new InputStreamReader(stream)) {
InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
return new ObjectMapper().readerFor(FieldConfig.class).readValue(reader);
}
}
Expand Down
2 changes: 1 addition & 1 deletion ntcore/src/generate/main/java/NetworkTableEntry.java.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,6 @@ public final class NetworkTableEntry implements Publisher, Subscriber {
}

private final Topic m_topic;
protected int m_handle;
private final int m_handle;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public NetworkTable getSubTable(String key) {
* @return true if the table as a value assigned to the given key
*/
public boolean containsKey(String key) {
return !("".equals(key)) && getTopic(key).exists();
return !"".equals(key) && getTopic(key).exists();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;

class PrintCommandTest extends CommandTestBase {
Expand All @@ -25,7 +26,7 @@ void printCommandScheduleTest() {
scheduler.run();

assertFalse(scheduler.isScheduled(command));
assertEquals(testOut.toString(), "Test!" + System.lineSeparator());
assertEquals(testOut.toString(StandardCharsets.UTF_8), "Test!" + System.lineSeparator());
} finally {
System.setOut(originalOut);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ private static long toULong(int sint) {

/** */
private static int toShort(int... buf) {
return (short) (((buf[0] & 0xFF) << 8) + ((buf[1] & 0xFF)));
return (short) (((buf[0] & 0xFF) << 8) + (buf[1] & 0xFF));
}

/** */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public boolean isConnected() {
* @return
*/
private static int toUShort(ByteBuffer buf) {
return (buf.getShort(0)) & 0xFFFF;
return buf.getShort(0) & 0xFFFF;
}

/**
Expand All @@ -469,7 +469,7 @@ private static long toULong(int sint) {
* @return
*/
private static int toShort(int... buf) {
return (short) (((buf[0] & 0xFF) << 8) + ((buf[1] & 0xFF)));
return (short) (((buf[0] & 0xFF) << 8) + (buf[1] & 0xFF));
}

/**
Expand Down Expand Up @@ -693,7 +693,7 @@ private int readRegister(int reg) {
private void writeRegister(int reg, int val) {
ByteBuffer buf = ByteBuffer.allocateDirect(2);
// low byte
buf.put(0, (byte) ((0x80 | reg)));
buf.put(0, (byte) (0x80 | reg));
buf.put(1, (byte) (val & 0xff));
m_spi.write(buf, 2);
// high byte
Expand Down
2 changes: 1 addition & 1 deletion wpilibj/src/main/java/edu/wpi/first/wpilibj/Servo.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void setAngle(double degrees) {
degrees = kMaxServoAngle;
}

setPosition(((degrees - kMinServoAngle)) / getServoAngleRange());
setPosition((degrees - kMinServoAngle) / getServoAngleRange());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("DifferentialDrive");
builder.setActuator(true);
builder.setSafeState(this::stopMotor);
builder.addDoubleProperty("Left Motor Speed", () -> m_leftOutput, m_leftMotor::accept);
builder.addDoubleProperty("Right Motor Speed", () -> m_rightOutput, m_rightMotor::accept);
builder.addDoubleProperty("Left Motor Speed", () -> m_leftOutput, m_leftMotor);
builder.addDoubleProperty("Right Motor Speed", () -> m_rightOutput, m_rightMotor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,10 @@ public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("MecanumDrive");
builder.setActuator(true);
builder.setSafeState(this::stopMotor);
builder.addDoubleProperty("Front Left Motor Speed", () -> m_frontLeftOutput, m_frontLeftMotor);
builder.addDoubleProperty(
"Front Left Motor Speed", () -> m_frontLeftOutput, m_frontLeftMotor::accept);
builder.addDoubleProperty(
"Front Right Motor Speed", () -> m_frontRightOutput, m_frontRightMotor::accept);
builder.addDoubleProperty(
"Rear Left Motor Speed", () -> m_rearLeftOutput, m_rearLeftMotor::accept);
builder.addDoubleProperty(
"Rear Right Motor Speed", () -> m_rearRightOutput, m_rearRightMotor::accept);
"Front Right Motor Speed", () -> m_frontRightOutput, m_frontRightMotor);
builder.addDoubleProperty("Rear Left Motor Speed", () -> m_rearLeftOutput, m_rearLeftMotor);
builder.addDoubleProperty("Rear Right Motor Speed", () -> m_rearRightOutput, m_rearRightMotor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other == null || getClass() != other.getClass()) {
if (!(other instanceof Color)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other == null || getClass() != other.getClass()) {
if (!(other instanceof Color8Bit)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public <Poses extends Num> Pose2d[] solve(Pose2d[] poses, int iterations) {
sum +=
m_cost.applyAsDouble(
poses[(int) state.get(i, 0)],
poses[(int) (state.get((i + 1) % poses.length, 0))]);
poses[(int) state.get((i + 1) % poses.length, 0)]);
}
return sum;
});
Expand Down
4 changes: 2 additions & 2 deletions wpiunits/src/main/java/edu/wpi/first/units/Mult.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected Mult(Class<? extends Mult<A, B>> baseType, A a, B b) {
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public static <A extends Unit<A>, B extends Unit<B>> Mult<A, B> combine(A a, B b) {
final long key = ((long) a.hashCode()) << 32L | ((long) b.hashCode()) & 0xFFFFFFFFL;
final long key = ((long) a.hashCode()) << 32L | (((long) b.hashCode()) & 0xFFFFFFFFL);
if (cache.containsKey(key)) {
return cache.get(key);
}
Expand Down Expand Up @@ -76,7 +76,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (!(o instanceof Mult)) {
return false;
}
if (!super.equals(o)) {
Expand Down
4 changes: 2 additions & 2 deletions wpiunits/src/main/java/edu/wpi/first/units/Per.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected Per(Class<Per<N, D>> baseType, N numerator, D denominator) {
public static <N extends Unit<N>, D extends Unit<D>> Per<N, D> combine(
N numerator, D denominator) {
final long key =
((long) numerator.hashCode()) << 32L | ((long) denominator.hashCode()) & 0xFFFFFFFFL;
((long) numerator.hashCode()) << 32L | (((long) denominator.hashCode()) & 0xFFFFFFFFL);

var existing = cache.get(key);
if (existing != null) {
Expand All @@ -83,7 +83,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (!(o instanceof Per)) {
return false;
}
if (!super.equals(o)) {
Expand Down
4 changes: 2 additions & 2 deletions wpiunits/src/main/java/edu/wpi/first/units/Velocity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Velocity<D extends Unit<D>> extends Unit<Velocity<D>> {

/** Generates a cache key used for cache lookups. */
private static long cacheKey(Unit<?> numerator, Unit<?> denominator) {
return ((long) numerator.hashCode()) << 32L | ((long) denominator.hashCode()) & 0xFFFFFFFFL;
return ((long) numerator.hashCode()) << 32L | (((long) denominator.hashCode()) & 0xFFFFFFFFL);
}

/**
Expand Down Expand Up @@ -152,7 +152,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (!(o instanceof Velocity)) {
return false;
}
if (!super.equals(o)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void testToLongString() {
var measure = Units.Volts.of(343);
assertEquals("343.0 Volt", measure.toLongString());
assertEquals("343.0001 Volt", Units.Volts.of(343.0001).toLongString());
assertEquals("1.2345678912345679E8 Volt", Units.Volts.of(123456789.123456789).toLongString());
assertEquals("1.2345678912345678E8 Volt", Units.Volts.of(123456789.12345678).toLongString());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static int preload(BufferedReader reader) {
* @return Number of classes loaded.
*/
public static int preload(InputStream stream) {
return preload(new BufferedReader(new InputStreamReader(stream)));
return preload(new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public String getField() {
}

@Override
public String toString() {
return m_field.isEmpty() ? getMessage() : "field " + m_field + ": " + getMessage();
public String getMessage() {
return m_field.isEmpty() ? super.getMessage() : "field " + m_field + ": " + super.getMessage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
package edu.wpi.first.util.struct;

import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;

/** Raw struct dynamic struct descriptor. */
public class StructDescriptor {
Expand Down Expand Up @@ -76,7 +76,7 @@ public List<StructFieldDescriptor> getFields() {
return m_fields;
}

boolean checkCircular(Stack<StructDescriptor> stack) {
boolean checkCircular(Deque<StructDescriptor> stack) {
stack.push(this);
for (StructDescriptor ref : m_references) {
if (stack.contains(ref)) {
Expand All @@ -90,7 +90,7 @@ boolean checkCircular(Stack<StructDescriptor> stack) {
return true;
}

void calculateOffsets(Stack<StructDescriptor> stack) {
void calculateOffsets(Deque<StructDescriptor> stack) {
int offset = 0;
int shift = 0;
int prevBitfieldSize = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import edu.wpi.first.util.struct.parser.ParsedDeclaration;
import edu.wpi.first.util.struct.parser.ParsedSchema;
import edu.wpi.first.util.struct.parser.Parser;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

/** Database of raw struct dynamic descriptors. */
public class StructDescriptorDatabase {
Expand Down Expand Up @@ -109,7 +110,7 @@ public StructDescriptor add(String name, String schema) throws BadSchemaExceptio
}

theStruct.m_valid = isValid;
Stack<StructDescriptor> stack = new Stack<>();
Deque<StructDescriptor> stack = new ArrayDeque<>();
if (isValid) {
// we have all the info needed, so calculate field offset & shift
theStruct.calculateOffsets(stack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public long getUintMax() {
* @return minimum value
*/
public long getIntMin() {
return (-(m_bitMask >> 1)) - 1;
return -(m_bitMask >> 1) - 1;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public int getPosition() {
}

@Override
public String toString() {
return m_pos + ": " + getMessage();
public String getMessage() {
return m_pos + ": " + super.getMessage();
}
}

0 comments on commit dedf60e

Please sign in to comment.