Skip to content

Commit a2499ab

Browse files
AustinShalitJLLeitschuh
authored andcommitted
Add Findbugs (#618)
* Add Findbugs * Fix existing findbugs errors
1 parent 547f897 commit a2499ab

32 files changed

+135
-36
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ install:
3030
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && ./gradlew :ui:jfxNative --stacktrace || ./gradlew --stacktrace '
3131

3232
script:
33-
- ./gradlew checkstyleMain checkstyleTest pmdMain pmdTest jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests
33+
- ./gradlew checkstyleMain checkstyleTest pmdMain pmdTest findbugsMain findbugsTest jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests
3434

3535
after_success:
3636
- if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then codecov ; fi

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build_script:
66

77
# to run your custom scripts instead of automatic tests
88
test_script:
9-
- gradlew.bat checkstyleMain checkstyleTest pmdMain pmdTest jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests
9+
- gradlew.bat checkstyleMain checkstyleTest pmdMain pmdTest findbugsMain findbugsTest jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests
1010

1111
platform:
1212
- x64

build.gradle

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import groovy.xml.XmlUtil
2+
13
buildscript {
24
repositories {
35
jcenter()
@@ -85,13 +87,14 @@ def getVersionSimple = { ->
8587
}
8688
}
8789

88-
configure(allprojects - project(':ui:linuxLauncher')) {
90+
configure(subprojects - project(':ui:linuxLauncher')) {
8991
apply plugin: 'java'
9092
apply plugin: 'application'
9193
apply plugin: 'jacoco'
9294
apply plugin: 'net.ltgt.errorprone'
9395
apply plugin: 'checkstyle'
9496
apply plugin: 'pmd'
97+
apply plugin: 'findbugs'
9598

9699
configurations.errorprone {
97100
resolutionStrategy.force 'com.google.errorprone:error_prone_core:2.0.9'
@@ -119,6 +122,30 @@ configure(allprojects - project(':ui:linuxLauncher')) {
119122
ruleSets = []
120123
}
121124

125+
findbugs {
126+
sourceSets = [sourceSets.main]
127+
excludeFilter = new File(rootDir, "findBugsSuppressions.xml")
128+
effort = "max"
129+
}
130+
131+
ext.printReportSafe = { xmlReport ->
132+
if (xmlReport.exists()) {
133+
def bugs = (new XmlParser().parse(xmlReport)).BugInstance
134+
bugs.each { System.out.println(new XmlUtil().serialize(it)) }
135+
}
136+
}
137+
138+
task findbugsMainReport << {
139+
printReportSafe(findbugsMain.reports.getXml().destination)
140+
}
141+
142+
task findbugsTestReport << {
143+
printReportSafe(findbugsTest.reports.getXml().destination)
144+
}
145+
146+
findbugsMain.finalizedBy findbugsMainReport
147+
findbugsTest.finalizedBy findbugsTestReport
148+
122149
repositories {
123150
mavenCentral()
124151
jcenter()
@@ -129,6 +156,7 @@ configure(allprojects - project(':ui:linuxLauncher')) {
129156

130157

131158
dependencies {
159+
compile group: 'com.google.code.findbugs', name: 'annotations', version: '3.0.1'
132160
testCompile group: 'net.jodah', name: 'concurrentunit', version: '0.4.2'
133161
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
134162
testCompile group: 'junit', name: 'junit', version: '4.12'

core/src/main/java/edu/wpi/grip/core/OperationDescription.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.Objects;
1010
import java.util.Optional;
1111
import java.util.Set;
12+
1213
import javax.annotation.Nullable;
1314
import javax.annotation.concurrent.Immutable;
1415

core/src/main/java/edu/wpi/grip/core/operations/composite/FilterContoursOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public void perform() {
191191
continue;
192192
}
193193

194-
final double ratio = bb.width() / bb.height();
194+
final double ratio = (double) bb.width() / (double) bb.height();
195195
if (ratio < minRatio || ratio > maxRatio) {
196196
continue;
197197
}

core/src/main/java/edu/wpi/grip/core/operations/composite/PublishVideoOperation.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import com.google.common.collect.ImmutableList;
1111

12+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
13+
1214
import org.bytedeco.javacpp.BytePointer;
1315
import org.bytedeco.javacpp.IntPointer;
1416

@@ -133,6 +135,8 @@ public class PublishVideoOperation implements Operation {
133135
};
134136

135137
@SuppressWarnings("JavadocMethod")
138+
@SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD",
139+
justification = "Do not need to synchronize inside of a constructor")
136140
public PublishVideoOperation(InputSocket.Factory inputSocketFactory) {
137141
if (numSteps != 0) {
138142
throw new IllegalStateException("Only one instance of PublishVideoOperation may exist");
@@ -141,7 +145,7 @@ public PublishVideoOperation(InputSocket.Factory inputSocketFactory) {
141145
false));
142146
this.qualitySocket = inputSocketFactory.create(SocketHints.Inputs
143147
.createNumberSliderSocketHint("Quality", 80, 0, 100));
144-
numSteps = numSteps + 1;
148+
numSteps++;
145149

146150
serverThread = new Thread(runServer, "Camera Server");
147151
serverThread.setDaemon(true);

core/src/main/java/edu/wpi/grip/core/operations/composite/ValveOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
public class ValveOperation implements Operation {
1818

19-
public static OperationDescription DESCRIPTION =
19+
public static final OperationDescription DESCRIPTION =
2020
OperationDescription.builder()
2121
.name("Valve")
2222
.summary("Toggle an output socket on or off using a boolean")

core/src/main/java/edu/wpi/grip/core/operations/network/http/DataHandler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import com.google.inject.Inject;
1313
import com.google.inject.Singleton;
1414

15+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
16+
1517
import org.eclipse.jetty.server.Request;
1618

1719
import java.io.IOException;
@@ -69,6 +71,8 @@ public final class DataHandler extends PedanticHandler {
6971
}
7072

7173
@Override
74+
@SuppressFBWarnings(value = "UW_UNCOND_WAIT",
75+
justification = "A bug in FindBugs. There is a condidtion (outside of the try)")
7276
protected void handleIfPassed(String target,
7377
Request baseRequest,
7478
HttpServletRequest request,

core/src/main/java/edu/wpi/grip/core/util/SafeShutdown.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package edu.wpi.grip.core.util;
22

3+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4+
35
import javax.annotation.Nullable;
46

57
/**
@@ -16,8 +18,11 @@ public final class SafeShutdown {
1618
* flagging a shutdown
1719
* that we can't control.
1820
*/
21+
1922
Runtime.getRuntime().addShutdownHook(new Thread() {
2023
@Override
24+
@SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD",
25+
justification = "Static variable is volatile")
2126
public void run() {
2227
SafeShutdown.stopping = true;
2328
}

core/src/test/java/edu/wpi/grip/core/ConnectionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void testPipelineSaysConnectionIsInvalid() {
6969
);
7070
}
7171

72-
private class MockPipeline extends Pipeline {
72+
private static class MockPipeline extends Pipeline {
7373
}
7474

7575

0 commit comments

Comments
 (0)