Skip to content

Commit d9b50aa

Browse files
authored
Integrate Error Prone for static code analysis (#1395)
* Add ErrorProne integration * Fix endless recursion due to missing delegation * Fix wrong generic type on Comparable for ZigBeeGroup * Fix wrong computation of hasCode for ZToolAddress64 * Fix wrong key being used for SynchronousCommandListener lookup * Make formatting of Integer explicit
1 parent ad326d1 commit d9b50aa

6 files changed

Lines changed: 66 additions & 11 deletions

File tree

com.zsmartsystems.zigbee.console/src/main/java/com/zsmartsystems/zigbee/console/ZigBeeConsoleOtaUpgradeCommand.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,16 @@ private void cmdDisplayAllNodes(ZigBeeNetworkManager networkManager, PrintStream
133133

134134
private void cmdDisplayNode(ZigBeeEndpoint endpoint, ZclOtaUpgradeServer otaServer, PrintStream out) {
135135
Object fileVersion = otaServer.getCurrentFileVersion();
136+
String fileVersionAsStr;
137+
if (fileVersion instanceof Integer) {
138+
fileVersionAsStr = String.format("%08X", ((Integer) fileVersion).intValue());
139+
} else {
140+
fileVersionAsStr = "Unknown";
141+
}
136142

137143
out.println("OTA Upgrade configuration for " + endpoint.getEndpointAddress());
138144
out.println("Current state : " + otaServer.getServerStatus());
139-
out.println("Firmware Version : " + (fileVersion == null ? "Unknown" : String.format("%08X", fileVersion)));
145+
out.println("Firmware Version : " + fileVersionAsStr);
140146
}
141147

142148
private Map<Integer, ZigBeeEndpoint> getApplications(ZigBeeNetworkManager networkManager, int clusterId) {

com.zsmartsystems.zigbee.dongle.cc2531/src/main/java/com/zsmartsystems/zigbee/dongle/cc2531/network/impl/CommandInterfaceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public void sendSynchronousCommand(final ZToolPacket packet, final SynchronousCo
242242
if (supportMultipleSynchrounsCommand) {
243243
synchronized (synchronousCommandListeners) {
244244
final short id = (short) (cmdId.get16BitValue() & 0x1FFF);
245-
while (synchronousCommandListeners.get(cmdId) != null) {
245+
while (synchronousCommandListeners.get(id) != null) {
246246
try {
247247
logger.trace("Waiting for other request {} to complete", id);
248248
synchronousCommandListeners.wait(500);

com.zsmartsystems.zigbee.dongle.cc2531/src/main/java/com/zsmartsystems/zigbee/dongle/cc2531/zigbee/util/ZToolAddress64.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
package com.zsmartsystems.zigbee.dongle.cc2531.zigbee.util;
3434

3535
import java.util.Arrays;
36-
import java.util.Objects;
3736

3837
/**
3938
* Big Endian container for 64-bit XBee Address
@@ -78,7 +77,7 @@ public void setAddress(byte[] address) {
7877

7978
@Override
8079
public int hashCode() {
81-
return Objects.hash(address);
80+
return Arrays.hashCode(address);
8281
}
8382

8483
@Override

com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/groups/ZigBeeGroup.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*
3939
* @author Chris Jackson
4040
*/
41-
public class ZigBeeGroup implements Comparable<Object> {
41+
public class ZigBeeGroup implements Comparable<ZigBeeGroup> {
4242
static final int MAX_LABEL_LENGTH = 16;
4343

4444
static final int GROUP_ID_MIN = 0x0000;
@@ -365,7 +365,7 @@ public int hashCode() {
365365
}
366366

367367
@Override
368-
public int compareTo(Object that) {
368+
public int compareTo(ZigBeeGroup that) {
369369
if (this == that) {
370370
return 0;
371371
}

com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/zcl/field/ZclArrayList.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ public void add(int index, Object element) {
144144

145145
@Override
146146
public Object remove(int index) {
147-
return remove(index);
147+
return list.remove(index);
148148
}
149149

150150
@Override
151151
public int indexOf(Object o) {
152-
return indexOf(o);
152+
return list.indexOf(o);
153153
}
154154

155155
@Override

pom.xml

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@
3939

4040
<properties>
4141
<license.year>2023</license.year>
42+
<source.version>1.8</source.version>
43+
<target.version>1.8</target.version>
4244
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4345
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
4446
<slf4j.version>1.7.30</slf4j.version>
4547
<log4j.version>1.2.17</log4j.version>
4648
<animal.sniffer.version>1.23</animal.sniffer.version>
49+
<error-prone.version>2.10.0</error-prone.version>
4750
</properties>
4851

4952
<scm>
@@ -126,17 +129,21 @@
126129
</signature>
127130
</configuration>
128131
</plugin>
132+
<plugin>
133+
<groupId>org.apache.maven.plugins</groupId>
134+
<artifactId>maven-compiler-plugin</artifactId>
135+
<version>3.8.0</version>
136+
</plugin>
129137
</plugins>
130138
</pluginManagement>
131139

132140
<plugins>
133141
<plugin>
134142
<groupId>org.apache.maven.plugins</groupId>
135143
<artifactId>maven-compiler-plugin</artifactId>
136-
<version>3.8.0</version>
137144
<configuration>
138-
<source>1.8</source>
139-
<target>1.8</target>
145+
<source>${source.version}</source>
146+
<target>${target.version}</target>
140147
<compilerArgs>-Xpkginfo:always</compilerArgs>
141148
</configuration>
142149
</plugin>
@@ -345,6 +352,49 @@
345352
</plugins>
346353
</build>
347354
</profile>
355+
<profile>
356+
<!--
357+
This profile can either be selected explicitly:
358+
mvn -P error-prone-check clean compile
359+
or implicitly by injecting a JDK in the version range [11,16)
360+
JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home mvn clean compile
361+
-->
362+
<id>error-prone-check</id>
363+
<activation>
364+
<!-- ErrorProne requires at least version 11 due to compiler hooks
365+
and starts to require additional flags with version 16... -->
366+
<jdk>[11,16)</jdk>
367+
</activation>
368+
<build>
369+
<plugins>
370+
<plugin>
371+
<groupId>org.apache.maven.plugins</groupId>
372+
<artifactId>maven-compiler-plugin</artifactId>
373+
<configuration combine.self="override">
374+
<source>${source.version}</source>
375+
<target>${target.version}</target>
376+
<encoding>${project.build.sourceEncoding}</encoding>
377+
<compilerArgs>
378+
<arg>-XDcompilePolicy=simple</arg>
379+
<arg>-Xplugin:ErrorProne</arg>
380+
</compilerArgs>
381+
<forceJavacCompilerUse>true</forceJavacCompilerUse>
382+
<annotationProcessorPaths>
383+
<path>
384+
<groupId>com.google.errorprone</groupId>
385+
<artifactId>error_prone_core</artifactId>
386+
<version>${error-prone.version}</version>
387+
</path>
388+
<!-- Other annotation processors go here.
389+
If 'annotationProcessorPaths' is set, processors will no longer be
390+
discovered on the regular -classpath; see also 'Using Error Prone
391+
together with other annotation processors' below. -->
392+
</annotationProcessorPaths>
393+
</configuration>
394+
</plugin>
395+
</plugins>
396+
</build>
397+
</profile>
348398
</profiles>
349399

350400
</project>

0 commit comments

Comments
 (0)