From 8968eb657aa4d1329091cc1a691a32a50c74a7f6 Mon Sep 17 00:00:00 2001 From: Austin Shalit Date: Thu, 7 Jul 2016 23:18:56 -0700 Subject: [PATCH 1/9] Add Findbugs --- .travis.yml | 2 +- appveyor.yml | 2 +- build.gradle | 12 ++++++++++++ findBugsSuppressions.xml | 8 ++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 findBugsSuppressions.xml diff --git a/.travis.yml b/.travis.yml index f7d3f6d3c8..bb0fe9f062 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ install: - '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && ./gradlew :ui:assemble --stacktrace || ./gradlew --stacktrace ' script: - - ./gradlew checkstyleMain checkstyleTest jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests + - ./gradlew checkstyleMain checkstyleTest findbugsMain findbugsTest jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests after_success: - if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then codecov ; fi diff --git a/appveyor.yml b/appveyor.yml index f348b3dccf..6d4fc7b801 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,7 +6,7 @@ build_script: # to run your custom scripts instead of automatic tests test_script: - - gradlew.bat checkstyleMain checkstyleTest jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests + - gradlew.bat checkstyleMain checkstyleTest findbugsMain findbugsTest jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests platform: - x64 diff --git a/build.gradle b/build.gradle index 4203c0759a..0d63ef0dc0 100644 --- a/build.gradle +++ b/build.gradle @@ -90,6 +90,7 @@ allprojects { apply plugin: 'jacoco' apply plugin: 'net.ltgt.errorprone' apply plugin: 'checkstyle' + apply plugin: 'findbugs' configurations.errorprone { resolutionStrategy.force 'com.google.errorprone:error_prone_core:2.0.9' @@ -106,6 +107,17 @@ allprojects { it.dependsOn = [] } + tasks.withType(FindBugs) { + it.dependsOn = [] + } + + findbugs { + // toolVersion = "2.0.1" + sourceSets = [sourceSets.main] + excludeFilter = new File(rootDir, "findBugsSuppressions.xml") + effort = "max" + } + repositories { mavenCentral() jcenter() diff --git a/findBugsSuppressions.xml b/findBugsSuppressions.xml new file mode 100644 index 0000000000..7f45c1c53b --- /dev/null +++ b/findBugsSuppressions.xml @@ -0,0 +1,8 @@ + + + + + + + + From 2cf74372075ca91f4998fb08e8e32c7474b903ce Mon Sep 17 00:00:00 2001 From: Austin Shalit Date: Fri, 8 Jul 2016 11:28:23 -0700 Subject: [PATCH 2/9] Fix Findbugs errors --- core/src/main/java/edu/wpi/grip/core/OperationDescription.java | 3 +-- .../core/operations/composite/FilterContoursOperation.java | 2 +- .../grip/core/operations/composite/PublishVideoOperation.java | 2 +- .../edu/wpi/grip/core/operations/composite/ValveOperation.java | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/edu/wpi/grip/core/OperationDescription.java b/core/src/main/java/edu/wpi/grip/core/OperationDescription.java index 2325bd7289..2960f6c1e6 100644 --- a/core/src/main/java/edu/wpi/grip/core/OperationDescription.java +++ b/core/src/main/java/edu/wpi/grip/core/OperationDescription.java @@ -9,7 +9,6 @@ import java.util.Optional; import java.util.Set; -import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; import static com.google.common.base.Preconditions.checkNotNull; @@ -95,7 +94,7 @@ public ImmutableSet aliases() { } @Override - public boolean equals(@Nullable Object o) { + public boolean equals(Object o) { if (this == o) { return true; } diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/FilterContoursOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/FilterContoursOperation.java index 20db252038..433ccd06cb 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/FilterContoursOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/FilterContoursOperation.java @@ -191,7 +191,7 @@ public void perform() { continue; } - final double ratio = bb.width() / bb.height(); + final double ratio = (double) bb.width() / (double) bb.height(); if (ratio < minRatio || ratio > maxRatio) { continue; } diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/PublishVideoOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/PublishVideoOperation.java index 2f2a167e9c..650faea62e 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/PublishVideoOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/PublishVideoOperation.java @@ -138,7 +138,7 @@ public PublishVideoOperation(InputSocket.Factory inputSocketFactory) { false)); this.qualitySocket = inputSocketFactory.create(SocketHints.Inputs .createNumberSliderSocketHint("Quality", 80, 0, 100)); - numSteps = numSteps + 1; + numSteps++; serverThread = new Thread(runServer, "Camera Server"); serverThread.setDaemon(true); diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/ValveOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/ValveOperation.java index e2af95c3cc..aff111cc08 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/ValveOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/ValveOperation.java @@ -16,7 +16,7 @@ public class ValveOperation implements Operation { - public static OperationDescription DESCRIPTION = + public static final OperationDescription DESCRIPTION = OperationDescription.builder() .name("Valve") .summary("Toggle an output socket on or off using a boolean") From 239d6195b1a56ffff5dcb5e19beecfe4d0210cf9 Mon Sep 17 00:00:00 2001 From: Austin Shalit Date: Fri, 8 Jul 2016 17:29:17 -0700 Subject: [PATCH 3/9] Print report --- build.gradle | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 0d63ef0dc0..202687f476 100644 --- a/build.gradle +++ b/build.gradle @@ -107,17 +107,28 @@ allprojects { it.dependsOn = [] } - tasks.withType(FindBugs) { - it.dependsOn = [] - } - findbugs { - // toolVersion = "2.0.1" sourceSets = [sourceSets.main] excludeFilter = new File(rootDir, "findBugsSuppressions.xml") effort = "max" } + task checkFindBugsReport << { + try { + def xmlReport = findbugsMain.reports.getXml() + def slurped = new XmlSlurper().parse(xmlReport.destination) + def bugsFound = slurped.BugInstance.size() + if (bugsFound > 0) { + new XmlNodePrinter().printList(slurped.BugInstance.list()) + throw new GradleException("$bugsFound FindBugs rule violations were found. See the report at: $xmlReport.destination") + } + } catch (Exception e) { + + } + } + + findbugsMain.finalizedBy checkFindBugsReport + repositories { mavenCentral() jcenter() From b4b9ad0e64a6325617b0dc03d19c959b3b576587 Mon Sep 17 00:00:00 2001 From: Austin Shalit Date: Wed, 3 Aug 2016 01:06:19 -0700 Subject: [PATCH 4/9] Fix printing --- build.gradle | 21 +++++++++++-------- .../wpi/grip/core/OperationDescription.java | 3 ++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index a200fb5ae9..9b3080a94c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,5 @@ +import groovy.xml.XmlUtil + buildscript { repositories { jcenter() @@ -124,23 +126,24 @@ configure(allprojects - project(':ui:linuxLauncher')) { sourceSets = [sourceSets.main] excludeFilter = new File(rootDir, "findBugsSuppressions.xml") effort = "max" + ignoreFailures = true // Error will be reported by checkFindBugsReport } task checkFindBugsReport << { - try { - def xmlReport = findbugsMain.reports.getXml() - def slurped = new XmlSlurper().parse(xmlReport.destination) - def bugsFound = slurped.BugInstance.size() + def xmlReport = findbugsMain.reports.getXml().destination + if (findbugsMain.reports.getXml().destination.exists()) { + def bugs = (new XmlParser().parse(xmlReport)).BugInstance + def bugsFound = bugs.size() if (bugsFound > 0) { - new XmlNodePrinter().printList(slurped.BugInstance.list()) - throw new GradleException("$bugsFound FindBugs rule violations were found. See the report at: $xmlReport.destination") + bugs.each { System.out.println(new XmlUtil().serialize(it)) } + throw new GradleException("$bugsFound FindBugs rule violations were found. See the report at: $xmlReport") } - } catch (Exception e) { - } } - findbugsMain.finalizedBy checkFindBugsReport + tasks.withType(FindBugs) { + it.finalizedBy checkFindBugsReport + } repositories { mavenCentral() diff --git a/core/src/main/java/edu/wpi/grip/core/OperationDescription.java b/core/src/main/java/edu/wpi/grip/core/OperationDescription.java index 88fafdd6c0..6647c3b996 100644 --- a/core/src/main/java/edu/wpi/grip/core/OperationDescription.java +++ b/core/src/main/java/edu/wpi/grip/core/OperationDescription.java @@ -10,6 +10,7 @@ import java.util.Optional; import java.util.Set; +import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; import static com.google.common.base.Preconditions.checkNotNull; @@ -95,7 +96,7 @@ public ImmutableSet aliases() { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) { return true; } From 8669cc2dca107d515eaf5932ae1e3ce7e32d12e8 Mon Sep 17 00:00:00 2001 From: Austin Shalit Date: Wed, 3 Aug 2016 01:31:56 -0700 Subject: [PATCH 5/9] Solve Bugs --- .travis.yml | 2 +- appveyor.yml | 2 +- build.gradle | 1 + .../core/operations/composite/PublishVideoOperation.java | 3 +++ .../wpi/grip/core/operations/network/http/DataHandler.java | 3 +++ core/src/main/java/edu/wpi/grip/core/util/SafeShutdown.java | 4 ++++ findBugsSuppressions.xml | 3 +++ .../java/edu/wpi/grip/ui/preview/BlobsSocketPreviewView.java | 5 ++++- .../java/edu/wpi/grip/ui/preview/LinesSocketPreviewView.java | 5 ++++- 9 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index adae4f5d49..370e296e0e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ install: - '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && ./gradlew :ui:jfxNative --stacktrace || ./gradlew --stacktrace ' script: - - ./gradlew checkstyleMain checkstyleTest pmdMain findbugsMain findbugsTest jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests + - ./gradlew checkstyleMain checkstyleTest pmdMain findbugsMain jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests after_success: - if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then codecov ; fi diff --git a/appveyor.yml b/appveyor.yml index e80ac45584..010ddbb114 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,7 +6,7 @@ build_script: # to run your custom scripts instead of automatic tests test_script: - - gradlew.bat checkstyleMain checkstyleTest pmdMain findbugsMain findbugsTest jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests + - gradlew.bat checkstyleMain checkstyleTest pmdMain findbugsMain jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests platform: - x64 diff --git a/build.gradle b/build.gradle index 9b3080a94c..c8e3ab87ba 100644 --- a/build.gradle +++ b/build.gradle @@ -155,6 +155,7 @@ configure(allprojects - project(':ui:linuxLauncher')) { dependencies { + compile group: 'com.google.code.findbugs', name: 'annotations', version: '3.0.1' testCompile group: 'net.jodah', name: 'concurrentunit', version: '0.4.2' testCompile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3' testCompile group: 'junit', name: 'junit', version: '4.12' diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/PublishVideoOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/PublishVideoOperation.java index 1f735a6de3..8ae64b5dcc 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/PublishVideoOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/PublishVideoOperation.java @@ -9,6 +9,8 @@ import com.google.common.collect.ImmutableList; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + import org.bytedeco.javacpp.BytePointer; import org.bytedeco.javacpp.IntPointer; @@ -133,6 +135,7 @@ public class PublishVideoOperation implements Operation { }; @SuppressWarnings("JavadocMethod") + @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD") // Don't need sync in constructor public PublishVideoOperation(InputSocket.Factory inputSocketFactory) { if (numSteps != 0) { throw new IllegalStateException("Only one instance of PublishVideoOperation may exist"); diff --git a/core/src/main/java/edu/wpi/grip/core/operations/network/http/DataHandler.java b/core/src/main/java/edu/wpi/grip/core/operations/network/http/DataHandler.java index b5801e33ce..fbd92bf058 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/network/http/DataHandler.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/network/http/DataHandler.java @@ -12,6 +12,8 @@ import com.google.inject.Inject; import com.google.inject.Singleton; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + import org.eclipse.jetty.server.Request; import java.io.IOException; @@ -69,6 +71,7 @@ public final class DataHandler extends PedanticHandler { } @Override + @SuppressFBWarnings("UW_UNCOND_WAIT") // Bug in FindBugs. There is a condition. protected void handleIfPassed(String target, Request baseRequest, HttpServletRequest request, diff --git a/core/src/main/java/edu/wpi/grip/core/util/SafeShutdown.java b/core/src/main/java/edu/wpi/grip/core/util/SafeShutdown.java index 1da37c7d1a..1762bbb01d 100644 --- a/core/src/main/java/edu/wpi/grip/core/util/SafeShutdown.java +++ b/core/src/main/java/edu/wpi/grip/core/util/SafeShutdown.java @@ -1,5 +1,7 @@ package edu.wpi.grip.core.util; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + import javax.annotation.Nullable; /** @@ -16,8 +18,10 @@ public final class SafeShutdown { * flagging a shutdown * that we can't control. */ + Runtime.getRuntime().addShutdownHook(new Thread() { @Override + @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD") public void run() { SafeShutdown.stopping = true; } diff --git a/findBugsSuppressions.xml b/findBugsSuppressions.xml index 7f45c1c53b..b5123c0a85 100644 --- a/findBugsSuppressions.xml +++ b/findBugsSuppressions.xml @@ -5,4 +5,7 @@ + + + diff --git a/ui/src/main/java/edu/wpi/grip/ui/preview/BlobsSocketPreviewView.java b/ui/src/main/java/edu/wpi/grip/ui/preview/BlobsSocketPreviewView.java index 288081b3c6..aa1abe4ec0 100644 --- a/ui/src/main/java/edu/wpi/grip/ui/preview/BlobsSocketPreviewView.java +++ b/ui/src/main/java/edu/wpi/grip/ui/preview/BlobsSocketPreviewView.java @@ -8,6 +8,8 @@ import com.google.common.eventbus.Subscribe; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + import javafx.application.Platform; import javafx.geometry.Orientation; import javafx.scene.control.CheckBox; @@ -38,7 +40,8 @@ public class BlobsSocketPreviewView extends SocketPreviewView { private final Mat tmp = new Mat(); private final GripPlatform platform; @SuppressWarnings("PMD.ImmutableField") - private boolean showInputImage; + @SuppressFBWarnings("IS2_INCONSISTENT_SYNC") // No sync needed in constructor + private boolean showInputImage = false; /** * @param socket An output socket to preview. diff --git a/ui/src/main/java/edu/wpi/grip/ui/preview/LinesSocketPreviewView.java b/ui/src/main/java/edu/wpi/grip/ui/preview/LinesSocketPreviewView.java index c79247d03c..878dd67e43 100644 --- a/ui/src/main/java/edu/wpi/grip/ui/preview/LinesSocketPreviewView.java +++ b/ui/src/main/java/edu/wpi/grip/ui/preview/LinesSocketPreviewView.java @@ -8,6 +8,8 @@ import com.google.common.eventbus.Subscribe; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + import java.util.List; import javafx.application.Platform; import javafx.geometry.Orientation; @@ -40,7 +42,8 @@ public class LinesSocketPreviewView extends SocketPreviewView { private final Mat tmp = new Mat(); private final GripPlatform platform; @SuppressWarnings("PMD.ImmutableField") - private boolean showInputImage; + @SuppressFBWarnings("IS2_INCONSISTENT_SYNC") // No sync needed in constructor + private boolean showInputImage = false; /** * @param socket An output socket to preview. From 1e21cb652d87f3e9018570473251c0666d1c2366 Mon Sep 17 00:00:00 2001 From: Austin Shalit Date: Thu, 4 Aug 2016 09:56:40 -0700 Subject: [PATCH 6/9] Add findbugsTest --- .travis.yml | 2 +- appveyor.yml | 2 +- build.gradle | 24 +++++++++++------------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 370e296e0e..adae4f5d49 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ install: - '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && ./gradlew :ui:jfxNative --stacktrace || ./gradlew --stacktrace ' script: - - ./gradlew checkstyleMain checkstyleTest pmdMain findbugsMain jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests + - ./gradlew checkstyleMain checkstyleTest pmdMain findbugsMain findbugsTest jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests after_success: - if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then codecov ; fi diff --git a/appveyor.yml b/appveyor.yml index 010ddbb114..e80ac45584 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,7 +6,7 @@ build_script: # to run your custom scripts instead of automatic tests test_script: - - gradlew.bat checkstyleMain checkstyleTest pmdMain findbugsMain jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests + - gradlew.bat checkstyleMain checkstyleTest pmdMain findbugsMain findbugsTest jacocoTestReport jacocoRootReport test --stacktrace -Pheadless=true -PlogTests platform: - x64 diff --git a/build.gradle b/build.gradle index c8e3ab87ba..a03c9c8522 100644 --- a/build.gradle +++ b/build.gradle @@ -126,25 +126,23 @@ configure(allprojects - project(':ui:linuxLauncher')) { sourceSets = [sourceSets.main] excludeFilter = new File(rootDir, "findBugsSuppressions.xml") effort = "max" - ignoreFailures = true // Error will be reported by checkFindBugsReport + ignoreFailures = true // Error will be reported below... } - task checkFindBugsReport << { - def xmlReport = findbugsMain.reports.getXml().destination - if (findbugsMain.reports.getXml().destination.exists()) { - def bugs = (new XmlParser().parse(xmlReport)).BugInstance - def bugsFound = bugs.size() - if (bugsFound > 0) { - bugs.each { System.out.println(new XmlUtil().serialize(it)) } - throw new GradleException("$bugsFound FindBugs rule violations were found. See the report at: $xmlReport") + tasks.withType(FindBugs) { + it.finalizedBy { + def xmlReport = it.reports.getXml().destination + if (xmlReport.exists()) { + def bugs = (new XmlParser().parse(xmlReport)).BugInstance + def bugsFound = bugs.size() + if (bugsFound > 0) { + bugs.each { System.out.println(new XmlUtil().serialize(it)) } + throw new GradleException("$bugsFound FindBugs rule violations were found. See the report at: $xmlReport") + } } } } - tasks.withType(FindBugs) { - it.finalizedBy checkFindBugsReport - } - repositories { mavenCentral() jcenter() From 5f2f107251398e7ca5d02b05da8471be06ac41a3 Mon Sep 17 00:00:00 2001 From: Austin Shalit Date: Sat, 6 Aug 2016 13:20:11 -0700 Subject: [PATCH 7/9] Fix printing (again) --- build.gradle | 33 ++++++++++--------- .../edu/wpi/grip/core/ConnectionTest.java | 2 +- .../edu/wpi/grip/core/PipelineRunnerTest.java | 5 +++ .../java/edu/wpi/grip/core/PipelineTest.java | 2 +- .../wpi/grip/core/http/GripServerTest.java | 3 +- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/build.gradle b/build.gradle index a03c9c8522..cdde67b931 100644 --- a/build.gradle +++ b/build.gradle @@ -87,7 +87,7 @@ def getVersionSimple = { -> } } -configure(allprojects - project(':ui:linuxLauncher')) { +configure(subprojects - project(':ui:linuxLauncher')) { apply plugin: 'java' apply plugin: 'application' apply plugin: 'jacoco' @@ -126,23 +126,26 @@ configure(allprojects - project(':ui:linuxLauncher')) { sourceSets = [sourceSets.main] excludeFilter = new File(rootDir, "findBugsSuppressions.xml") effort = "max" - ignoreFailures = true // Error will be reported below... - } - - tasks.withType(FindBugs) { - it.finalizedBy { - def xmlReport = it.reports.getXml().destination - if (xmlReport.exists()) { - def bugs = (new XmlParser().parse(xmlReport)).BugInstance - def bugsFound = bugs.size() - if (bugsFound > 0) { - bugs.each { System.out.println(new XmlUtil().serialize(it)) } - throw new GradleException("$bugsFound FindBugs rule violations were found. See the report at: $xmlReport") - } - } + } + + ext.printReportSafe = { xmlReport -> + if (xmlReport.exists()) { + def bugs = (new XmlParser().parse(xmlReport)).BugInstance + bugs.each { System.out.println(new XmlUtil().serialize(it)) } } } + task findbugsMainReport << { + printReportSafe(findbugsMain.reports.getXml().destination) + } + + task findbugsTestReport << { + printReportSafe(findbugsTest.reports.getXml().destination) + } + + findbugsMain.finalizedBy findbugsMainReport + findbugsTest.finalizedBy findbugsTestReport + repositories { mavenCentral() jcenter() diff --git a/core/src/test/java/edu/wpi/grip/core/ConnectionTest.java b/core/src/test/java/edu/wpi/grip/core/ConnectionTest.java index 00acd780af..ab2099cf5e 100644 --- a/core/src/test/java/edu/wpi/grip/core/ConnectionTest.java +++ b/core/src/test/java/edu/wpi/grip/core/ConnectionTest.java @@ -71,7 +71,7 @@ public void testPipelineSaysConnectionIsInvalid() { ); } - private class MockPipeline extends Pipeline { + private static class MockPipeline extends Pipeline { } diff --git a/core/src/test/java/edu/wpi/grip/core/PipelineRunnerTest.java b/core/src/test/java/edu/wpi/grip/core/PipelineRunnerTest.java index 6b61d50751..7136833dfc 100644 --- a/core/src/test/java/edu/wpi/grip/core/PipelineRunnerTest.java +++ b/core/src/test/java/edu/wpi/grip/core/PipelineRunnerTest.java @@ -14,6 +14,9 @@ import com.google.common.eventbus.Subscribe; import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.Service; + +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + import net.jodah.concurrentunit.Waiter; import org.junit.After; import org.junit.Before; @@ -141,6 +144,8 @@ class ExceptionEventReceiver { private ExceptionEvent event; @Subscribe + @SuppressFBWarnings(value = "UMAC_UNCALLABLE_METHOD_OF_ANONYMOUS_CLASS", + justification = "EventBus can call this method") public void onException(ExceptionEvent event) { this.event = event; callCount++; diff --git a/core/src/test/java/edu/wpi/grip/core/PipelineTest.java b/core/src/test/java/edu/wpi/grip/core/PipelineTest.java index a93a51a38a..e7f5445b55 100644 --- a/core/src/test/java/edu/wpi/grip/core/PipelineTest.java +++ b/core/src/test/java/edu/wpi/grip/core/PipelineTest.java @@ -381,7 +381,7 @@ public void testMoveStepToRight() { Arrays.asList(lowerStep, stepToMove, upperStep), pipeline.getSteps()); } - private class MockConnection extends Connection { + private static class MockConnection extends Connection { /** * @param pipeline The pipeline to create the connection inside of. diff --git a/core/src/test/java/edu/wpi/grip/core/http/GripServerTest.java b/core/src/test/java/edu/wpi/grip/core/http/GripServerTest.java index 101e7733af..ddffbc169f 100644 --- a/core/src/test/java/edu/wpi/grip/core/http/GripServerTest.java +++ b/core/src/test/java/edu/wpi/grip/core/http/GripServerTest.java @@ -19,6 +19,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; +import java.nio.charset.Charset; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -71,7 +72,7 @@ public void testAddRemoveHandler() throws IOException { didRun[0] = true; }); instance.addHandler(h); - HttpResponse response = doPost(path, path.getBytes()); + HttpResponse response = doPost(path, path.getBytes(Charset.defaultCharset())); EntityUtils.consume(response.getEntity()); assertTrue("Handler should have run", didRun[0]); didRun[0] = false; From 540ddab6dc52a328723f89ae9e0aa7837c9684b1 Mon Sep 17 00:00:00 2001 From: Austin Shalit Date: Sat, 6 Aug 2016 13:26:26 -0700 Subject: [PATCH 8/9] Add justification --- .../grip/core/operations/composite/PublishVideoOperation.java | 3 ++- .../edu/wpi/grip/core/operations/network/http/DataHandler.java | 3 ++- core/src/main/java/edu/wpi/grip/core/util/SafeShutdown.java | 3 ++- .../java/edu/wpi/grip/ui/preview/BlobsSocketPreviewView.java | 3 ++- .../java/edu/wpi/grip/ui/preview/LinesSocketPreviewView.java | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/edu/wpi/grip/core/operations/composite/PublishVideoOperation.java b/core/src/main/java/edu/wpi/grip/core/operations/composite/PublishVideoOperation.java index 8ae64b5dcc..a30153bb9b 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/composite/PublishVideoOperation.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/composite/PublishVideoOperation.java @@ -135,7 +135,8 @@ public class PublishVideoOperation implements Operation { }; @SuppressWarnings("JavadocMethod") - @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD") // Don't need sync in constructor + @SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", + justification = "Do not need to synchronize inside of a constructor") public PublishVideoOperation(InputSocket.Factory inputSocketFactory) { if (numSteps != 0) { throw new IllegalStateException("Only one instance of PublishVideoOperation may exist"); diff --git a/core/src/main/java/edu/wpi/grip/core/operations/network/http/DataHandler.java b/core/src/main/java/edu/wpi/grip/core/operations/network/http/DataHandler.java index fbd92bf058..395e0b4e09 100644 --- a/core/src/main/java/edu/wpi/grip/core/operations/network/http/DataHandler.java +++ b/core/src/main/java/edu/wpi/grip/core/operations/network/http/DataHandler.java @@ -71,7 +71,8 @@ public final class DataHandler extends PedanticHandler { } @Override - @SuppressFBWarnings("UW_UNCOND_WAIT") // Bug in FindBugs. There is a condition. + @SuppressFBWarnings(value = "UW_UNCOND_WAIT", + justification = "A bug in FindBugs. There is a condidtion (outside of the try)") protected void handleIfPassed(String target, Request baseRequest, HttpServletRequest request, diff --git a/core/src/main/java/edu/wpi/grip/core/util/SafeShutdown.java b/core/src/main/java/edu/wpi/grip/core/util/SafeShutdown.java index 1762bbb01d..cb47c58755 100644 --- a/core/src/main/java/edu/wpi/grip/core/util/SafeShutdown.java +++ b/core/src/main/java/edu/wpi/grip/core/util/SafeShutdown.java @@ -21,7 +21,8 @@ public final class SafeShutdown { Runtime.getRuntime().addShutdownHook(new Thread() { @Override - @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD") + @SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", + justification = "Static variable is volatile") public void run() { SafeShutdown.stopping = true; } diff --git a/ui/src/main/java/edu/wpi/grip/ui/preview/BlobsSocketPreviewView.java b/ui/src/main/java/edu/wpi/grip/ui/preview/BlobsSocketPreviewView.java index aa1abe4ec0..b282252c85 100644 --- a/ui/src/main/java/edu/wpi/grip/ui/preview/BlobsSocketPreviewView.java +++ b/ui/src/main/java/edu/wpi/grip/ui/preview/BlobsSocketPreviewView.java @@ -40,7 +40,8 @@ public class BlobsSocketPreviewView extends SocketPreviewView { private final Mat tmp = new Mat(); private final GripPlatform platform; @SuppressWarnings("PMD.ImmutableField") - @SuppressFBWarnings("IS2_INCONSISTENT_SYNC") // No sync needed in constructor + @SuppressFBWarnings(value = "IS2_INCONSISTENT_SYNC", + justification = "Do not need to synchronize inside of a constructor") private boolean showInputImage = false; /** diff --git a/ui/src/main/java/edu/wpi/grip/ui/preview/LinesSocketPreviewView.java b/ui/src/main/java/edu/wpi/grip/ui/preview/LinesSocketPreviewView.java index 878dd67e43..85985464a6 100644 --- a/ui/src/main/java/edu/wpi/grip/ui/preview/LinesSocketPreviewView.java +++ b/ui/src/main/java/edu/wpi/grip/ui/preview/LinesSocketPreviewView.java @@ -42,7 +42,8 @@ public class LinesSocketPreviewView extends SocketPreviewView { private final Mat tmp = new Mat(); private final GripPlatform platform; @SuppressWarnings("PMD.ImmutableField") - @SuppressFBWarnings("IS2_INCONSISTENT_SYNC") // No sync needed in constructor + @SuppressFBWarnings(value = "IS2_INCONSISTENT_SYNC", + justification = "Do not need to synchronize inside of a constructor") private boolean showInputImage = false; /** From 67cf8998af36bee891a1b865be37daba30d05ca3 Mon Sep 17 00:00:00 2001 From: Austin Shalit Date: Sat, 6 Aug 2016 15:26:00 -0700 Subject: [PATCH 9/9] Solve Test Bugs --- .../wpi/grip/core/http/GripServerTest.java | 11 ++++----- .../core/http/HttpPipelineSwitcherTest.java | 3 ++- .../grip/core/http/NoContextHandlerTest.java | 4 +++- .../grip/core/http/PedanticHandlerTest.java | 4 +++- .../core/serialization/CompatibilityTest.java | 24 +++++++++++-------- .../grip/core/serialization/ProjectTest.java | 1 - .../edu/wpi/grip/core/sockets/SocketTest.java | 6 +++++ .../grip/core/sources/CameraSourceTest.java | 8 +++++-- .../grip/core/util/ExceptionWitnessTest.java | 2 +- .../service/AutoRestartingServiceTest.java | 8 ++++--- .../edu/wpi/grip/util/GripCoreTestModule.java | 4 ++++ .../java/edu/wpi/grip/ui/PaletteTest.java | 5 +++- .../components/PreviousNextButtonsTest.java | 2 +- .../grip/ui/pipeline/AddSourceButtonTest.java | 4 ++-- .../pipeline/OutputSocketControllerTest.java | 2 +- .../wpi/grip/ui/util/ControllerMapTest.java | 4 ++-- .../wpi/grip/ui/util/GripPlatformTest.java | 4 ++++ 17 files changed, 63 insertions(+), 33 deletions(-) diff --git a/core/src/test/java/edu/wpi/grip/core/http/GripServerTest.java b/core/src/test/java/edu/wpi/grip/core/http/GripServerTest.java index ddffbc169f..06c15653d5 100644 --- a/core/src/test/java/edu/wpi/grip/core/http/GripServerTest.java +++ b/core/src/test/java/edu/wpi/grip/core/http/GripServerTest.java @@ -19,8 +19,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; -import java.nio.charset.Charset; - +import java.nio.charset.StandardCharsets; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -72,12 +71,12 @@ public void testAddRemoveHandler() throws IOException { didRun[0] = true; }); instance.addHandler(h); - HttpResponse response = doPost(path, path.getBytes(Charset.defaultCharset())); + HttpResponse response = doPost(path, path.getBytes(StandardCharsets.UTF_8)); EntityUtils.consume(response.getEntity()); assertTrue("Handler should have run", didRun[0]); didRun[0] = false; instance.removeHandler(h); - response = doPost(path, path.getBytes()); + response = doPost(path, path.getBytes(StandardCharsets.UTF_8)); EntityUtils.consume(response.getEntity()); assertFalse("Handler should not have run", didRun[0]); } @@ -90,7 +89,7 @@ public void testSuccessfulHandler() throws IOException { didRun[0] = true; }); instance.addHandler(h); - doPost(path, path.getBytes()); + doPost(path, path.getBytes(StandardCharsets.UTF_8)); assertTrue("Handler should have run on " + path, didRun[0]); } @@ -103,7 +102,7 @@ public void testUnsuccessfulPostHandler() throws Exception { throw new GripServerException("Expected"); }); instance.addHandler(h); - HttpResponse response = doPost(path, path.getBytes()); + HttpResponse response = doPost(path, path.getBytes(StandardCharsets.UTF_8)); assertEquals("Server should return an internal error (500)", 500, response.getStatusLine().getStatusCode()); diff --git a/core/src/test/java/edu/wpi/grip/core/http/HttpPipelineSwitcherTest.java b/core/src/test/java/edu/wpi/grip/core/http/HttpPipelineSwitcherTest.java index f04eb9cb82..fe6a00b893 100644 --- a/core/src/test/java/edu/wpi/grip/core/http/HttpPipelineSwitcherTest.java +++ b/core/src/test/java/edu/wpi/grip/core/http/HttpPipelineSwitcherTest.java @@ -17,6 +17,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; +import java.nio.charset.StandardCharsets; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -121,7 +122,7 @@ private HttpResponse doGet(String path) throws IOException { private HttpResponse doPost(String path, String text) throws IOException { HttpPost post = new HttpPost("http://localhost:" + server.getPort() + path); BasicHttpEntity httpEntity = new BasicHttpEntity(); - httpEntity.setContent(new ByteArrayInputStream(text.getBytes())); + httpEntity.setContent(new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8))); post.setEntity(httpEntity); return client.execute(post); } diff --git a/core/src/test/java/edu/wpi/grip/core/http/NoContextHandlerTest.java b/core/src/test/java/edu/wpi/grip/core/http/NoContextHandlerTest.java index a690548b70..c6ca1912c1 100644 --- a/core/src/test/java/edu/wpi/grip/core/http/NoContextHandlerTest.java +++ b/core/src/test/java/edu/wpi/grip/core/http/NoContextHandlerTest.java @@ -18,6 +18,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; +import java.nio.charset.StandardCharsets; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -71,7 +72,8 @@ public void tearDown() throws Exception { private CloseableHttpResponse sendHttpRequest(String path) throws IOException { HttpPost post = new HttpPost("http://localhost:" + getServerPort() + path); BasicHttpEntity httpEntity = new BasicHttpEntity(); - httpEntity.setContent(new ByteArrayInputStream("http_request_bytes".getBytes())); + httpEntity.setContent( + new ByteArrayInputStream("http_request_bytes".getBytes(StandardCharsets.UTF_8))); post.setEntity(httpEntity); return client.execute(post); } diff --git a/core/src/test/java/edu/wpi/grip/core/http/PedanticHandlerTest.java b/core/src/test/java/edu/wpi/grip/core/http/PedanticHandlerTest.java index 67d34c79e1..b95b88f663 100644 --- a/core/src/test/java/edu/wpi/grip/core/http/PedanticHandlerTest.java +++ b/core/src/test/java/edu/wpi/grip/core/http/PedanticHandlerTest.java @@ -16,6 +16,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; +import java.nio.charset.StandardCharsets; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -100,7 +101,8 @@ private static T[] arr(T... a) { private void sendHttpRequest(String path) throws IOException { HttpPost post = new HttpPost("http://localhost:" + getServerPort() + path); BasicHttpEntity httpEntity = new BasicHttpEntity(); - httpEntity.setContent(new ByteArrayInputStream("http_request_bytes".getBytes())); + httpEntity.setContent( + new ByteArrayInputStream("http_request_bytes".getBytes(StandardCharsets.UTF_8))); post.setEntity(httpEntity); HttpResponse resp = client.execute(post); EntityUtils.consume(resp.getEntity()); diff --git a/core/src/test/java/edu/wpi/grip/core/serialization/CompatibilityTest.java b/core/src/test/java/edu/wpi/grip/core/serialization/CompatibilityTest.java index 9ca78dab19..69f4f9b3df 100644 --- a/core/src/test/java/edu/wpi/grip/core/serialization/CompatibilityTest.java +++ b/core/src/test/java/edu/wpi/grip/core/serialization/CompatibilityTest.java @@ -16,10 +16,14 @@ import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.io.Reader; +import java.io.Writer; import java.net.URI; +import java.nio.charset.StandardCharsets; import static junit.framework.TestCase.assertEquals; @@ -60,22 +64,22 @@ public void setUp() throws Exception { //Open the project save file and read it into a string so that we can alter it File file = new File(fileName); - Reader temp = new FileReader(file); + Reader temp = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8); BufferedReader reader = new BufferedReader(temp); String line = ""; - String oldText = ""; + StringBuffer oldText = new StringBuffer(); while ((line = reader.readLine()) != null) { - oldText += line + "\r\n"; + oldText.append(line).append("\r\n"); } reader.close(); - String newText = oldText.replaceAll("REPLACEME", photoFileName); //This gives the correct - // location of the test photo needed to the project file + String newText = oldText.toString().replaceAll("REPLACEME", photoFileName); //This gives the + // correct location of the test photo needed to the project file //Write the altered project file text - FileWriter writer2 = new FileWriter(file); - writer2.write(newText); + Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8); + writer.write(newText); - writer2.close(); + writer.close(); //Open the test file as a project project.open(file); diff --git a/core/src/test/java/edu/wpi/grip/core/serialization/ProjectTest.java b/core/src/test/java/edu/wpi/grip/core/serialization/ProjectTest.java index e62021d756..013cd2f0eb 100644 --- a/core/src/test/java/edu/wpi/grip/core/serialization/ProjectTest.java +++ b/core/src/test/java/edu/wpi/grip/core/serialization/ProjectTest.java @@ -154,7 +154,6 @@ public void testSerializePipelineWithStepsAndConnections() throws Exception { final Step step2 = stepFactory.create(pythonAdditionOperationFromURL); final InputSocket a2 = (InputSocket) step2.getInputSockets().get(0); final InputSocket b2 = (InputSocket) step2.getInputSockets().get(1); - final OutputSocket sum2 = (OutputSocket) step2.getOutputSockets().get(0); a1.setValue(12); b1.setValue(34); diff --git a/core/src/test/java/edu/wpi/grip/core/sockets/SocketTest.java b/core/src/test/java/edu/wpi/grip/core/sockets/SocketTest.java index 7062106514..dc0cb22a24 100644 --- a/core/src/test/java/edu/wpi/grip/core/sockets/SocketTest.java +++ b/core/src/test/java/edu/wpi/grip/core/sockets/SocketTest.java @@ -6,6 +6,8 @@ import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + import org.junit.Before; import org.junit.Test; @@ -51,6 +53,8 @@ public void testSocketChangedEvent() throws Exception { final boolean[] handled = new boolean[]{false}; final Double[] value = new Double[]{0.0}; Object eventHandler = new Object() { + @SuppressFBWarnings(value = "UMAC_UNCALLABLE_METHOD_OF_ANONYMOUS_CLASS", + justification = "This method is called by Guava's EventBus") @Subscribe public void onSocketChanged(SocketChangedEvent e) { handled[0] = true; @@ -73,6 +77,8 @@ public void testSocketPreview() { final boolean[] handled = new boolean[]{false}; Object eventHandler = new Object() { + @SuppressFBWarnings(value = "UMAC_UNCALLABLE_METHOD_OF_ANONYMOUS_CLASS", + justification = "This method is called by Guava's EventBus") @Subscribe public void onSocketPreviewed(SocketPreviewChangedEvent e) { handled[0] = true; diff --git a/core/src/test/java/edu/wpi/grip/core/sources/CameraSourceTest.java b/core/src/test/java/edu/wpi/grip/core/sources/CameraSourceTest.java index adf3422c54..063e592b32 100644 --- a/core/src/test/java/edu/wpi/grip/core/sources/CameraSourceTest.java +++ b/core/src/test/java/edu/wpi/grip/core/sources/CameraSourceTest.java @@ -15,6 +15,8 @@ import com.google.inject.Guice; import com.google.inject.Injector; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + import net.jodah.concurrentunit.Waiter; import org.bytedeco.javacpp.indexer.Indexer; @@ -61,6 +63,8 @@ public void setUp() throws Exception { final EventBus eventBus = new EventBus(); class UnhandledExceptionWitness { + @SuppressFBWarnings(value = "UMAC_UNCALLABLE_METHOD_OF_ANONYMOUS_CLASS", + justification = "This method is called by Guava's EventBus") @Subscribe public void onUnexpectedThrowableEvent(UnexpectedThrowableEvent event) { event.handleSafely((throwable, message, isFatal) -> { @@ -250,7 +254,7 @@ public FrameGrabber create(String addressProperty) throws MalformedURLException } } - class MockFrameGrabber extends FrameGrabber { + static class MockFrameGrabber extends FrameGrabber { private final Frame frame; private final Indexer frameIdx; private boolean shouldThrowAtStart = false; @@ -306,7 +310,7 @@ public void setShouldThrowAtStop(boolean shouldThrowAtStop) { } } - class MockFrameGrabberFactory implements CameraSource.FrameGrabberFactory { + static class MockFrameGrabberFactory implements CameraSource.FrameGrabberFactory { private MockFrameGrabber frameGrabber = new MockFrameGrabber(); @Override diff --git a/core/src/test/java/edu/wpi/grip/core/util/ExceptionWitnessTest.java b/core/src/test/java/edu/wpi/grip/core/util/ExceptionWitnessTest.java index 4cef964cff..50402b4668 100644 --- a/core/src/test/java/edu/wpi/grip/core/util/ExceptionWitnessTest.java +++ b/core/src/test/java/edu/wpi/grip/core/util/ExceptionWitnessTest.java @@ -77,7 +77,7 @@ private void fireAnError() { /** * Used to count the number of calls that ExceptionEvent and ExceptionClearedEvent fires. */ - private class TestWitnessListener { + private static class TestWitnessListener { private int errorRunCount = 0; private int clearRunCount = 0; private Optional errorWitnessObserver = Optional.empty(); diff --git a/core/src/test/java/edu/wpi/grip/core/util/service/AutoRestartingServiceTest.java b/core/src/test/java/edu/wpi/grip/core/util/service/AutoRestartingServiceTest.java index 4c189bb232..a626fbee42 100644 --- a/core/src/test/java/edu/wpi/grip/core/util/service/AutoRestartingServiceTest.java +++ b/core/src/test/java/edu/wpi/grip/core/util/service/AutoRestartingServiceTest.java @@ -4,6 +4,8 @@ import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.Service; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -39,6 +41,8 @@ public class AutoRestartingServiceTest { private Throwable thrownByExecutionThread; private Executor exceptionCatchingExecutor; + @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD", + justification = "A JUnit rule -- used by JUnit") @Rule public Timeout timeout = new Timeout(10, TimeUnit.SECONDS); @@ -210,7 +214,7 @@ public void stopping(Service.State from) { /** * Records all instances of the object returned by {@link Supplier#get()} */ - private class RecordingSupplier implements Supplier { + private static class RecordingSupplier implements Supplier { private final LinkedList services = new LinkedList<>(); private final Supplier serviceSupplier; @@ -278,7 +282,6 @@ protected Executor executor() { } private class WaitThenThrowOnRunService extends AbstractExecutionThreadService { - private boolean shutDownCalled = false; private boolean throwOnShutDown = false; private CountDownLatch runLatch = new CountDownLatch(1); @@ -290,7 +293,6 @@ protected void run() throws InterruptedException { @Override protected void shutDown() { - shutDownCalled = true; if (throwOnShutDown) { throw new UnsupportedOperationException("double kaboom!"); } diff --git a/core/src/test/java/edu/wpi/grip/util/GripCoreTestModule.java b/core/src/test/java/edu/wpi/grip/util/GripCoreTestModule.java index bfb3c2155c..bbbeb437bf 100644 --- a/core/src/test/java/edu/wpi/grip/util/GripCoreTestModule.java +++ b/core/src/test/java/edu/wpi/grip/util/GripCoreTestModule.java @@ -13,6 +13,8 @@ import com.google.common.eventbus.SubscriberExceptionContext; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + import java.util.ArrayList; import java.util.List; import java.util.concurrent.ConcurrentLinkedQueue; @@ -30,6 +32,8 @@ * that exceptions always get dumped for the test that has just run. */ public class GripCoreTestModule extends GripCoreModule { + @SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", + justification = "Member is volatile") private static volatile boolean instanceAlive = false; private final ConcurrentLinkedQueue threadExceptions = new diff --git a/ui/src/test/java/edu/wpi/grip/ui/PaletteTest.java b/ui/src/test/java/edu/wpi/grip/ui/PaletteTest.java index 1ea7b749f1..4581a9bac5 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/PaletteTest.java +++ b/ui/src/test/java/edu/wpi/grip/ui/PaletteTest.java @@ -16,6 +16,8 @@ import com.google.inject.Injector; import com.google.inject.util.Modules; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + import org.junit.Test; import org.testfx.framework.junit.ApplicationTest; import org.testfx.util.WaitForAsyncUtils; @@ -23,7 +25,6 @@ import java.io.IOException; import java.util.Collections; import java.util.List; - import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.stage.Stage; @@ -64,6 +65,8 @@ public void testPalette() { // Record when a a StepAddedEvent happens Step[] step = new Step[]{null}; eventBus.register(new Object() { + @SuppressFBWarnings(value = "UMAC_UNCALLABLE_METHOD_OF_ANONYMOUS_CLASS", + justification = "This method is called by Guava's EventBus") @Subscribe public void onStepAdded(StepAddedEvent event) { step[0] = event.getStep(); diff --git a/ui/src/test/java/edu/wpi/grip/ui/components/PreviousNextButtonsTest.java b/ui/src/test/java/edu/wpi/grip/ui/components/PreviousNextButtonsTest.java index b92b325868..e3c88c9cb1 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/components/PreviousNextButtonsTest.java +++ b/ui/src/test/java/edu/wpi/grip/ui/components/PreviousNextButtonsTest.java @@ -60,7 +60,7 @@ public void testClickNext() { .isSelected()); } - class MockPreviousNext implements PreviousNext { + static class MockPreviousNext implements PreviousNext { private int index; diff --git a/ui/src/test/java/edu/wpi/grip/ui/pipeline/AddSourceButtonTest.java b/ui/src/test/java/edu/wpi/grip/ui/pipeline/AddSourceButtonTest.java index 16eeb24937..9baac12eab 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/pipeline/AddSourceButtonTest.java +++ b/ui/src/test/java/edu/wpi/grip/ui/pipeline/AddSourceButtonTest.java @@ -88,7 +88,7 @@ public void testCreatesSourceStarted() throws Exception { verifyThat("." + AddSourceButton.SOURCE_DIALOG_STYLE_CLASS, NodeMatchers.isNull()); } - class MockCameraSourceFactory implements CameraSource.Factory { + static class MockCameraSourceFactory implements CameraSource.Factory { private final EventBus eventBus; private Optional lastSourceCreated = Optional.empty(); @@ -176,7 +176,7 @@ public void testCreatesSourceStartedFails() throws Exception { .isRunning()); } - class MockCameraSourceFactory implements CameraSource.Factory { + static class MockCameraSourceFactory implements CameraSource.Factory { private final EventBus eventBus; private Optional lastSourceCreated = Optional.empty(); diff --git a/ui/src/test/java/edu/wpi/grip/ui/pipeline/OutputSocketControllerTest.java b/ui/src/test/java/edu/wpi/grip/ui/pipeline/OutputSocketControllerTest.java index 1624c71f74..b62943d6c9 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/pipeline/OutputSocketControllerTest.java +++ b/ui/src/test/java/edu/wpi/grip/ui/pipeline/OutputSocketControllerTest.java @@ -69,7 +69,7 @@ public void testInitiallyPreviewedOutputSocket() { initiallyPreviewedOutputSocketController.previewButton().isSelected()); } - private class InitiallyPreviewedOutputSocket extends MockOutputSocket { + private static class InitiallyPreviewedOutputSocket extends MockOutputSocket { public InitiallyPreviewedOutputSocket(String socketName) { super(socketName); this.setPreviewed(true); diff --git a/ui/src/test/java/edu/wpi/grip/ui/util/ControllerMapTest.java b/ui/src/test/java/edu/wpi/grip/ui/util/ControllerMapTest.java index 5cbeb9f3fa..ff6ab75196 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/util/ControllerMapTest.java +++ b/ui/src/test/java/edu/wpi/grip/ui/util/ControllerMapTest.java @@ -110,7 +110,7 @@ public void testTryToModifyManagedList() throws Exception { }); } - private class MockPane extends Pane { + private static class MockPane extends Pane { private final ControllerMap controllerMap; @@ -121,7 +121,7 @@ public MockPane() { } - private class MockController implements Controller { + private static class MockController implements Controller { private final Pane pane = new Pane(); diff --git a/ui/src/test/java/edu/wpi/grip/ui/util/GripPlatformTest.java b/ui/src/test/java/edu/wpi/grip/ui/util/GripPlatformTest.java index 90fedeb0b5..a670492610 100644 --- a/ui/src/test/java/edu/wpi/grip/ui/util/GripPlatformTest.java +++ b/ui/src/test/java/edu/wpi/grip/ui/util/GripPlatformTest.java @@ -2,6 +2,8 @@ import com.google.common.eventbus.EventBus; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + import net.jodah.concurrentunit.Waiter; import org.junit.Before; @@ -20,6 +22,8 @@ public class GripPlatformTest extends ApplicationTest { + @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD", + justification = "A JUnit rule -- used by JUnit") @Rule public Timeout globalTimeout = Timeout.seconds(10); // 10 seconds max per method tested private EventBus eventBus;