Skip to content

Commit

Permalink
[build] Upgrade to PMD 7.2.0 (#6718)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold856 authored Jun 9, 2024
1 parent e2dcbd0 commit b0cc84a
Show file tree
Hide file tree
Showing 64 changed files with 148 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,11 @@ public int hashCode() {
private static class FieldDimensions {
@SuppressWarnings("MemberName")
@JsonProperty(value = "length")
public double fieldLength;
public final double fieldLength;

@SuppressWarnings("MemberName")
@JsonProperty(value = "width")
public double fieldWidth;
public final double fieldWidth;

@JsonCreator()
FieldDimensions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public final class OpenCvLoader {
static boolean libraryLoaded;

/** Sets whether JNI should be loaded in the static block. */
public static class Helper {
public static final class Helper {
private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true);

/**
Expand Down
3 changes: 3 additions & 0 deletions cscore/src/main/java/edu/wpi/first/cscore/VideoListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ public boolean isValid() {

private static final ReentrantLock s_lock = new ReentrantLock();
private static final Map<Integer, Consumer<VideoEvent>> s_listeners = new HashMap<>();

@SuppressWarnings("PMD.SingularField")
private static Thread s_thread;

private static int s_poller;
private static boolean s_waitQueue;
private static final Condition s_waitQueueCond = s_lock.newCondition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,5 @@ public String[] getChoices() {
}

int m_handle;
private Kind m_kind;
private final Kind m_kind;
}
1 change: 1 addition & 0 deletions hal/src/generate/FRCNetComm.java.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package edu.wpi.first.hal;
/**
* JNI wrapper for library <b>FRC_NetworkCommunication</b><br>.
*/
@SuppressWarnings("PMD.MissingStaticMethodInNonInstantiatableClass")
public final class FRCNetComm {
/**
* Resource type from UsageReporting.
Expand Down

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

4 changes: 2 additions & 2 deletions hal/src/main/java/edu/wpi/first/hal/HAL.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public final class HAL extends JNIWrapper {

private static final List<Runnable> s_simPeriodicBefore = new ArrayList<>();

public static class SimPeriodicBeforeCallback implements AutoCloseable {
public static final class SimPeriodicBeforeCallback implements AutoCloseable {
private SimPeriodicBeforeCallback(Runnable r) {
m_run = r;
}
Expand Down Expand Up @@ -128,7 +128,7 @@ public static void simPeriodicBefore() {

private static final List<Runnable> s_simPeriodicAfter = new ArrayList<>();

public static class SimPeriodicAfterCallback implements AutoCloseable {
public static final class SimPeriodicAfterCallback implements AutoCloseable {
private SimPeriodicAfterCallback(Runnable r) {
m_run = r;
}
Expand Down
9 changes: 1 addition & 8 deletions ntcore/src/generate/main/java/NetworkTableEntry.java.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -541,14 +541,7 @@ public final class NetworkTableEntry implements Publisher, Subscriber {

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
if (!(other instanceof NetworkTableEntry)) {
return false;
}

return m_handle == ((NetworkTableEntry) other).m_handle;
return other == this || other instanceof NetworkTableEntry entry && m_handle == entry.m_handle;
}

@Override
Expand Down
9 changes: 4 additions & 5 deletions ntcore/src/generate/main/java/NetworkTableInstance.java.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import us.hebi.quickbuf.ProtoMessage;
* kept to the NetworkTableInstance returned by this function to keep it from being garbage
* collected.
*/
@SuppressWarnings("PMD.CouplingBetweenObjects")
public final class NetworkTableInstance implements AutoCloseable {
/** Client/server mode flag values (as returned by {@link #getNetworkMode()}). */
public enum NetworkMode {
Expand Down Expand Up @@ -493,7 +492,10 @@ public final class NetworkTableInstance implements AutoCloseable {
private static class ListenerStorage implements AutoCloseable {
private final ReentrantLock m_lock = new ReentrantLock();
private final Map<Integer, Consumer<NetworkTableEvent>> m_listeners = new HashMap<>();

@SuppressWarnings("PMD.SingularField")
private Thread m_thread;

private int m_poller;
private boolean m_waitQueue;
private final Event m_waitQueueEvent = new Event();
Expand Down Expand Up @@ -1239,10 +1241,7 @@ public final class NetworkTableInstance implements AutoCloseable {

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
return other instanceof NetworkTableInstance inst && m_handle == inst.m_handle;
return other == this || other instanceof NetworkTableInstance inst && m_handle == inst.m_handle;
}

@Override
Expand Down
10 changes: 4 additions & 6 deletions ntcore/src/generate/main/java/NetworkTableValue.java.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,10 @@ public final class NetworkTableValue {
{% endfor %}
@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
return other instanceof NetworkTableValue ntOther
&& m_type == ntOther.m_type
&& m_value.equals(ntOther.m_value);
return other == this
|| other instanceof NetworkTableValue ntOther
&& m_type == ntOther.m_type
&& m_value.equals(ntOther.m_value);
}

@Override
Expand Down

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

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

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 @@ -18,7 +18,6 @@
import us.hebi.quickbuf.ProtoMessage;

/** A network table that knows its subtable path. */
@SuppressWarnings("PMD.CouplingBetweenObjects")
public final class NetworkTable {
/** The path separator for sub-tables and keys. */
public static final char PATH_SEPARATOR = '/';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,10 @@ public ProtobufEntry<T> getEntry(T defaultValue, PubSubOption... options) {

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
return other instanceof ProtobufTopic<?> topic
&& super.equals(topic)
&& m_proto == topic.m_proto;
return other == this
|| other instanceof ProtobufTopic<?> topic
&& super.equals(topic)
&& m_proto == topic.m_proto;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,10 @@ public Struct<T> getStruct() {

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
return other instanceof StructArrayTopic<?> topic
&& super.equals(topic)
&& m_struct == topic.m_struct;
return other == this
|| other instanceof StructArrayTopic<?> topic
&& super.equals(topic)
&& m_struct == topic.m_struct;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,10 @@ public Struct<T> getStruct() {

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
return other instanceof StructTopic<?> topic
&& super.equals(topic)
&& m_struct == topic.m_struct;
return other == this
|| other instanceof StructTopic<?> topic
&& super.equals(topic)
&& m_struct == topic.m_struct;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion shared/java/javastyle.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ checkstyle {
apply plugin: 'pmd'

pmd {
toolVersion = '6.55.0'
toolVersion = '7.2.0'
consoleOutput = true
reportsDir = file("$project.buildDir/reports/pmd")
ruleSetFiles = files(new File(rootDir, "styleguide/pmd-ruleset.xml"))
Expand Down
17 changes: 9 additions & 8 deletions styleguide/pmd-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,28 @@
value=".*'.*Arguments\(\)'.*" />
</properties>
</rule>
<rule ref="category/java/bestpractices.xml/UnusedLocalVariable">
<properties>
<property name="violationSuppressXPath" value="//Resource"/>
</properties>
</rule>

<rule ref="category/java/design.xml">
<exclude name="AvoidThrowingRawExceptionTypes" />
<exclude name="AvoidThrowingNewInstanceOfSameException" />
<exclude name="CognitiveComplexity" />
<exclude name="CouplingBetweenObjects" />
<exclude name="CyclomaticComplexity" />
<exclude name="DataClass" />
<exclude name="ExcessiveClassLength" />
<exclude name="ExceptionAsFlowControl" />
<exclude name="ExcessiveImports" />
<exclude name="ExcessiveMethodLength" />
<exclude name="ExcessiveParameterList" />
<exclude name="ExcessivePublicCount" />
<exclude name="GodClass" />
<exclude name="LawOfDemeter" />
<exclude name="LoosePackageCoupling" />
<exclude name="NPathComplexity" />
<exclude name="NcssConstructorCount" />
<exclude name="NcssCount" />
<exclude name="NcssMethodCount" />
<exclude name="TooManyFields" />
<exclude name="TooManyMethods" />
</rule>
Expand All @@ -67,10 +71,8 @@
<exclude name="AvoidLiteralsInIfCondition" />
<exclude name="CloseResource" />
<exclude name="ConstructorCallsOverridableMethod" />
<exclude name="DataflowAnomalyAnalysis" />
<exclude name="DoNotTerminateVM" />
<exclude name="EmptyCatchBlock" />
<exclude name="EmptyWhileStmt" />
<exclude name="FinalizeDoesNotCallSuperFinalize" />
<exclude name="JUnitSpelling" />
<exclude name="MissingSerialVersionUID" />
Expand All @@ -86,7 +88,6 @@
</rule>

<rule ref="category/java/performance.xml">
<exclude name="AvoidUsingShortType" />
<exclude name="AvoidInstantiatingObjectsInLoops" />
</rule>

Expand All @@ -98,7 +99,7 @@
<!-- Custom Rules -->
<rule name="UseRequireNonNull"
message="Use Objects.requireNonNull() instead of throwing a NullPointerException yourself."
language="java" class="net.sourceforge.pmd.lang.rule.XPathRule">
language="java" class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
<description>Use Objects.requireNonNull() instead of throwing a
NullPointerException yourself.</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public ParallelRaceGroup(Command... commands) {
*
* @param commands Commands to add to the group.
*/
@SuppressWarnings("PMD.UseArraysAsList")
public final void addCommands(Command... commands) {
if (!m_finished) {
throw new IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public SequentialCommandGroup(Command... commands) {
*
* @param commands Commands to add, in order of execution.
*/
@SuppressWarnings("PMD.UseArraysAsList")
public final void addCommands(Command... commands) {
if (m_currentCommandIndex != -1) {
throw new IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void cleanup() {
new SwerveModuleState(0, Rotation2d.kZero)
};

private SwerveModulePosition[] m_modulePositions =
private final SwerveModulePosition[] m_modulePositions =
new SwerveModulePosition[] {
new SwerveModulePosition(0, Rotation2d.kZero),
new SwerveModulePosition(0, Rotation2d.kZero),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ private void acquire() {

if (calc_crc == imu_crc) {
// Timestamp is at buffer[i]
m_dt = ((double) buffer[i] - previous_timestamp) / 1000000.0;
m_dt = (buffer[i] - previous_timestamp) / 1000000.0;

// Scale sensor data
gyro_rate_x = (toShort(buffer[i + 5], buffer[i + 6]) * 0.04);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ private void acquire() {
// Could be multiple data sets in the buffer. Handle each one.
for (int i = 0; i < data_to_read; i += dataset_len) {
// Timestamp is at buffer[i]
m_dt = ((double) buffer[i] - previous_timestamp) / 1000000.0;
m_dt = (buffer[i] - previous_timestamp) / 1000000.0;

/*
* System.out.println(((toInt(buffer[i + 3], buffer[i + 4], buffer[i + 5],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public int getPeriodCycles() {
public long getPeriodNanoSeconds() {
int fpgaCycles = getPeriodCycles();

return (long) fpgaCycles * 1000L / (long) (SensorUtil.kSystemClockTicksPerMicrosecond / 4);
return fpgaCycles * 1000L / (SensorUtil.kSystemClockTicksPerMicrosecond / 4);
}

@Override
Expand Down
Loading

0 comments on commit b0cc84a

Please sign in to comment.