Skip to content

Commit

Permalink
Integrate Error Prone for static code analysis (#1395)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ViToni committed May 5, 2023
1 parent ad326d1 commit d9b50aa
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,16 @@ private void cmdDisplayAllNodes(ZigBeeNetworkManager networkManager, PrintStream

private void cmdDisplayNode(ZigBeeEndpoint endpoint, ZclOtaUpgradeServer otaServer, PrintStream out) {
Object fileVersion = otaServer.getCurrentFileVersion();
String fileVersionAsStr;
if (fileVersion instanceof Integer) {
fileVersionAsStr = String.format("%08X", ((Integer) fileVersion).intValue());
} else {
fileVersionAsStr = "Unknown";
}

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

private Map<Integer, ZigBeeEndpoint> getApplications(ZigBeeNetworkManager networkManager, int clusterId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public void sendSynchronousCommand(final ZToolPacket packet, final SynchronousCo
if (supportMultipleSynchrounsCommand) {
synchronized (synchronousCommandListeners) {
final short id = (short) (cmdId.get16BitValue() & 0x1FFF);
while (synchronousCommandListeners.get(cmdId) != null) {
while (synchronousCommandListeners.get(id) != null) {
try {
logger.trace("Waiting for other request {} to complete", id);
synchronousCommandListeners.wait(500);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
package com.zsmartsystems.zigbee.dongle.cc2531.zigbee.util;

import java.util.Arrays;
import java.util.Objects;

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

@Override
public int hashCode() {
return Objects.hash(address);
return Arrays.hashCode(address);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*
* @author Chris Jackson
*/
public class ZigBeeGroup implements Comparable<Object> {
public class ZigBeeGroup implements Comparable<ZigBeeGroup> {
static final int MAX_LABEL_LENGTH = 16;

static final int GROUP_ID_MIN = 0x0000;
Expand Down Expand Up @@ -365,7 +365,7 @@ public int hashCode() {
}

@Override
public int compareTo(Object that) {
public int compareTo(ZigBeeGroup that) {
if (this == that) {
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ public void add(int index, Object element) {

@Override
public Object remove(int index) {
return remove(index);
return list.remove(index);
}

@Override
public int indexOf(Object o) {
return indexOf(o);
return list.indexOf(o);
}

@Override
Expand Down
56 changes: 53 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@

<properties>
<license.year>2023</license.year>
<source.version>1.8</source.version>
<target.version>1.8</target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<slf4j.version>1.7.30</slf4j.version>
<log4j.version>1.2.17</log4j.version>
<animal.sniffer.version>1.23</animal.sniffer.version>
<error-prone.version>2.10.0</error-prone.version>
</properties>

<scm>
Expand Down Expand Up @@ -126,17 +129,21 @@
</signature>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>${source.version}</source>
<target>${target.version}</target>
<compilerArgs>-Xpkginfo:always</compilerArgs>
</configuration>
</plugin>
Expand Down Expand Up @@ -345,6 +352,49 @@
</plugins>
</build>
</profile>
<profile>
<!--
This profile can either be selected explicitly:
mvn -P error-prone-check clean compile
or implicitly by injecting a JDK in the version range [11,16)
JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home mvn clean compile
-->
<id>error-prone-check</id>
<activation>
<!-- ErrorProne requires at least version 11 due to compiler hooks
and starts to require additional flags with version 16... -->
<jdk>[11,16)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration combine.self="override">
<source>${source.version}</source>
<target>${target.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
<compilerArgs>
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne</arg>
</compilerArgs>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<annotationProcessorPaths>
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>${error-prone.version}</version>
</path>
<!-- Other annotation processors go here.
If 'annotationProcessorPaths' is set, processors will no longer be
discovered on the regular -classpath; see also 'Using Error Prone
together with other annotation processors' below. -->
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>

0 comments on commit d9b50aa

Please sign in to comment.