Skip to content

Commit b66935e

Browse files
authored
Fix spotbugs on CI (#1019)
2 parents de5339f + 5183a6b commit b66935e

File tree

9 files changed

+31
-22
lines changed

9 files changed

+31
-22
lines changed

.circleci/config.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ anchors:
4242
path: lib-extra/build/test-results/test
4343
- store_test_results:
4444
path: plugin-gradle/build/test-results/test
45+
- store_artifacts:
46+
path: lib/build/spotbugs
47+
- store_artifacts:
48+
path: lib-extra/build/spotbugs
49+
- store_artifacts:
50+
path: testlib/build/spotbugs
51+
- store_artifacts:
52+
path: plugin-gradle/build/spotbugs
53+
4554
jobs:
4655
# gradlew spotlessCheck assemble testClasses
4756
assemble_testClasses:
@@ -108,22 +117,14 @@ jobs:
108117
- store_test_results:
109118
path: plugin-gradle/build/test-results/NpmTest
110119
- run:
111-
name: gradlew check
112-
command: export SPOTLESS_EXCLUDE_MAVEN=true && ./gradlew check --build-cache
120+
name: gradlew test
121+
command: export SPOTLESS_EXCLUDE_MAVEN=true && ./gradlew test --build-cache
113122
- store_test_results:
114123
path: testlib/build/test-results/test
115124
- store_test_results:
116125
path: lib-extra/build/test-results/test
117126
- store_test_results:
118127
path: plugin-gradle/build/test-results/test
119-
- store_artifacts:
120-
path: lib/build/spotbugs
121-
- store_artifacts:
122-
path: lib-extra/build/spotbugs
123-
- store_artifacts:
124-
path: testlib/build/spotbugs
125-
- store_artifacts:
126-
path: plugin-gradle/build/spotbugs
127128
test_windows:
128129
executor:
129130
name: win/default

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ artifactIdGradle=spotless-plugin-gradle
1515

1616
# Build requirements
1717
VER_JAVA=1.8
18-
VER_SPOTBUGS=4.0.2
18+
VER_SPOTBUGS=4.5.0
1919

2020
# Dependencies provided by Spotless plugin
2121
VER_SLF4J=[1.6,2.0[

gradle/java-setup.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ spotbugs {
1919
ignoreFailures = false // bug free or it doesn't ship!
2020
reportsDir = file('build/spotbugs')
2121
reportLevel = 'medium' // low|medium|high (low = sensitive to even minor mistakes)
22-
omitVisitors = [] // bugs that we want to ignore
22+
omitVisitors = [
23+
'FindReturnRef'] // https://spotbugs.readthedocs.io/en/latest/detectors.html#findreturnref
2324
}
2425
tasks.named('spotbugsTest') {
2526
enabled = false
2627
}
2728
tasks.named('spotbugsMain') {
2829
// only run on Java 8 (no benefit to running twice)
29-
enabled = org.gradle.api.JavaVersion.current() == org.gradle.api.JavaVersion.VERSION_1_8
30+
enabled = org.gradle.api.JavaVersion.current() == org.gradle.api.JavaVersion.VERSION_11
3031
reports {
3132
html.enabled = true
3233
}

lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ protected Repository repositoryFor(Project project) throws IOException {
169169

170170
protected abstract @Nullable Project getParent(Project project);
171171

172-
private static @Nullable Repository traverseParentsUntil(File startWith, File file) throws IOException {
172+
private static @Nullable Repository traverseParentsUntil(File startWith, @Nullable File file) throws IOException {
173173
while (startWith != null && !Objects.equals(startWith, file)) {
174174
if (isGitRoot(startWith)) {
175175
return createRepo(startWith);

lib/src/main/java/com/diffplug/spotless/FormatterProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 DiffPlug
2+
* Copyright 2016-2021 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -93,7 +93,7 @@ private void add(final File settingsFile) throws IllegalArgumentException {
9393
try {
9494
Properties newSettings = FileParser.parse(settingsFile);
9595
properties.putAll(newSettings);
96-
} catch (IOException | IllegalArgumentException | NullPointerException exception) {
96+
} catch (IOException | IllegalArgumentException exception) {
9797
String message = String.format("Failed to add properties from '%s' to formatter settings.", settingsFile);
9898
String detailedMessage = exception.getMessage();
9999
if (null != detailedMessage) {

lib/src/main/java/com/diffplug/spotless/PaddedCell.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import java.util.Objects;
3030
import java.util.function.Function;
3131

32+
import javax.annotation.Nullable;
33+
3234
/**
3335
* Models the result of applying a {@link Formatter} on a given {@link File}
3436
* while characterizing various failure modes (slow convergence, cycles, and divergence).
@@ -240,9 +242,10 @@ public static DirtyState calculateDirtyState(Formatter formatter, File file, byt
240242
* then you can call {@link #writeCanonicalTo(OutputStream)} to get the canonical form of the given file.
241243
*/
242244
public static class DirtyState {
245+
@Nullable
243246
private final byte[] canonicalBytes;
244247

245-
private DirtyState(byte[] canonicalBytes) {
248+
private DirtyState(@Nullable byte[] canonicalBytes) {
246249
this.canonicalBytes = canonicalBytes;
247250
}
248251

lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static LicenseHeaderStep headerDelimiter(ThrowingEx.Supplier<String> head
6161
final String yearSeparator;
6262
final Supplier<YearMode> yearMode;
6363

64-
private LicenseHeaderStep(String name, String contentPattern, ThrowingEx.Supplier<String> headerLazy, String delimiter, String yearSeparator, Supplier<YearMode> yearMode) {
64+
private LicenseHeaderStep(@Nullable String name, @Nullable String contentPattern, ThrowingEx.Supplier<String> headerLazy, String delimiter, String yearSeparator, Supplier<YearMode> yearMode) {
6565
this.name = sanitizeName(name);
6666
this.contentPattern = sanitizeContentPattern(contentPattern);
6767
this.headerLazy = Objects.requireNonNull(headerLazy);
@@ -141,7 +141,7 @@ public FormatterStep build() {
141141
return formatterStep.filterByContentPattern(contentPattern);
142142
}
143143

144-
private String sanitizeName(String name) {
144+
private String sanitizeName(@Nullable String name) {
145145
if (name == null) {
146146
return DEFAULT_NAME_PREFIX;
147147
}
@@ -156,7 +156,7 @@ private String sanitizeName(String name) {
156156
}
157157

158158
@Nullable
159-
private String sanitizeContentPattern(String contentPattern) {
159+
private String sanitizeContentPattern(@Nullable String contentPattern) {
160160
if (contentPattern == null) {
161161
return contentPattern;
162162
}

lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import com.diffplug.spotless.FormatterFunc;
3636
import com.diffplug.spotless.FormatterStep;
3737

38+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
39+
3840
public final class ImportOrderStep {
3941
private static final boolean WILDCARDS_LAST_DEFAULT = false;
4042

@@ -77,6 +79,7 @@ private FormatterStep createFrom(boolean wildcardsLast, Supplier<List<String>> i
7779
State::toFormatter);
7880
}
7981

82+
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE") // workaround https://github.com/spotbugs/spotbugs/issues/756
8083
private static List<String> getImportOrder(File importsFile) {
8184
try (Stream<String> lines = Files.lines(importsFile.toPath())) {
8285
return lines.filter(line -> !line.startsWith("#"))

lib/src/main/java/com/diffplug/spotless/npm/SimpleRestClient.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 DiffPlug
2+
* Copyright 2016-2021 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@
2626
import java.util.Map;
2727

2828
import javax.annotation.Nonnull;
29+
import javax.annotation.Nullable;
2930

3031
class SimpleRestClient {
3132
private final String baseUrl;
@@ -49,7 +50,7 @@ String post(String endpoint) throws SimpleRestException {
4950
return postJson(endpoint, (String) null);
5051
}
5152

52-
String postJson(String endpoint, String rawJson) throws SimpleRestException {
53+
String postJson(String endpoint, @Nullable String rawJson) throws SimpleRestException {
5354
try {
5455
URL url = new URL(this.baseUrl + endpoint);
5556
HttpURLConnection con = (HttpURLConnection) url.openConnection();

0 commit comments

Comments
 (0)