Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt "errorprone" tool instead of Spotbugs #1525

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ repositories {

dependencies {
implementation 'com.diffplug.spotless:spotless-plugin-gradle:6.25.0'
implementation 'com.github.spotbugs.snom:spotbugs-gradle-plugin:6.0.15'
implementation 'net.ltgt.gradle:gradle-errorprone-plugin:4.0.0'
}
45 changes: 28 additions & 17 deletions buildSrc/src/main/groovy/rhino.library-conventions.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
plugins {
id 'rhino.java-conventions'
id 'com.github.spotbugs'
id 'maven-publish'
id 'checkstyle'
id 'jacoco'
id 'net.ltgt.errorprone'
}

import com.github.spotbugs.snom.Confidence
import com.github.spotbugs.snom.Effort
dependencies {
errorprone "com.google.errorprone:error_prone_core:2.28.0"
}

version = project.version

Expand All @@ -26,20 +27,30 @@ tasks.withType(Jar).configureEach {
}
}

spotbugs {
effort = Effort.valueOf('LESS')
reportLevel = Confidence.valueOf('MEDIUM')
excludeFilter = file("${projectDir}/../config/spotbugs/spotbugs-exclude.xml")
}

spotbugsMain {
reports {
html {
required = true
outputLocation = file("$buildDir/reports/spotbugs/main/spotbugs.html")
stylesheet = 'fancy-hist.xsl'
}
}
tasks.withType(JavaCompile).configureEach {
options.errorprone.disable(
// JavaDoc stuff
"AlmostJavadoc",
"EmptyBlockTag",
"EscapedEntity",
"MissingSummary",
"InvalidBlockTag",
"InvalidLink",
"InvalidParam",
"NotJavadoc",
"UnicodeEscape",
// Great ideas for when minimum version is more than Java 11
"PatternMatchingInstanceof",
// Stuff that we just love to do but should do less of eventually
"EmptyCatch",
"LabelledBreakTarget",
"JavaUtilDate",
// Less important for now, more stylistic than bug
"InlineMeSuggester",
// This one either alerts for parameters that we don't use,
// or spuriously for local variables in my opinion.
"UnusedVariable")
options.errorprone.excludedPaths = '.+/src/test/java/.+'
}

jacocoTestReport {
Expand Down
166 changes: 0 additions & 166 deletions config/spotbugs/spotbugs-exclude.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import javax.script.ScriptContext;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
Expand All @@ -30,7 +31,7 @@ public class Builtins {

void register(Context cx, ScriptableObject scope, ScriptContext sc) {
if (sc.getWriter() == null) {
stdout = new OutputStreamWriter(System.out);
stdout = new OutputStreamWriter(System.out, StandardCharsets.UTF_8);
} else {
stdout = sc.getWriter();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -78,10 +79,10 @@ public class Dim {
/**
* Synchronization object used to allow script evaluations to happen when a thread is resumed.
*/
private Object monitor = new Object();
private final Object monitor = new Object();

/** Synchronization object used to wait for valid {@link #interruptedContextData}. */
private Object eventThreadMonitor = new Object();
private final Object eventThreadMonitor = new Object();

/** The action to perform to end the interruption loop. */
private volatile int returnValue = -1;
Expand Down Expand Up @@ -254,11 +255,11 @@ private String loadSource(String sourceUrl) {
}
}

is = (new URL(sourceUrl)).openStream();
is = new URL(sourceUrl).openStream();
}

try {
source = Kit.readReader(new InputStreamReader(is));
source = Kit.readReader(new InputStreamReader(is, StandardCharsets.UTF_8));
} finally {
is.close();
}
Expand Down Expand Up @@ -1130,6 +1131,9 @@ public static class SourceInfo {
/** Array indicating whether a breakpoint is set on the line. */
private boolean[] breakpoints;

/** Lock for same */
private final Object breakpointsLock = new Object();

/** Array of FunctionSource objects for the functions in the script. */
private FunctionSource[] functionSources;

Expand Down Expand Up @@ -1260,7 +1264,7 @@ public boolean breakpoint(int line, boolean value) {
throw new IllegalArgumentException(String.valueOf(line));
}
boolean changed;
synchronized (breakpoints) {
synchronized (breakpointsLock) {
if (breakpoints[line] != value) {
breakpoints[line] = value;
changed = true;
Expand All @@ -1273,7 +1277,7 @@ public boolean breakpoint(int line, boolean value) {

/** Removes all breakpoints from the script. */
public void removeAllBreakpoints() {
synchronized (breakpoints) {
synchronized (breakpointsLock) {
for (int line = 0; line != breakpoints.length; ++line) {
breakpoints[line] = false;
}
Expand Down
Loading
Loading