Skip to content

Commit de9c855

Browse files
author
Vincent Potucek
committed
Add error-prone.picnic.tech featuring StaticImport
1 parent 343017b commit de9c855

File tree

39 files changed

+162
-141
lines changed

39 files changed

+162
-141
lines changed

gradle/libs.versions.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ bndlib = { module = "biz.aQute.bnd:biz.aQute.bndlib", version.ref = "bnd" }
3232
checkstyle = { module = "com.puppycrawl.tools:checkstyle", version.ref = "checkstyle" }
3333
classgraph = { module = "io.github.classgraph:classgraph", version = "4.8.181" }
3434
commons-io = { module = "commons-io:commons-io", version = "2.20.0" }
35-
errorProne-core = { module = "com.google.errorprone:error_prone_core", version = "2.42.0" }
35+
error-prone-core = { module = "com.google.errorprone:error_prone_core", version = "2.42.0" }
36+
error-prone-contrib = { module = "tech.picnic.error-prone-support:error-prone-contrib", version = "0.25.0" }
37+
refaster-runner = { module = "tech.picnic.error-prone-support:refaster-runner", version = "0.25.0" }
3638
fastcsv = { module = "de.siegmar:fastcsv", version = "4.0.0" }
3739
groovy = { module = "org.apache.groovy:groovy", version = "5.0.1" }
3840
groovy2-bom = { module = "org.codehaus.groovy:groovy-bom", version = "2.5.23" }

gradle/plugins/common/src/main/kotlin/junitbuild.java-nullability-conventions.gradle.kts

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import junitbuild.extensions.dependencyFromLibs
22
import net.ltgt.gradle.errorprone.errorprone
33
import net.ltgt.gradle.nullaway.nullaway
4+
import java.lang.System.getenv
45

56
plugins {
67
`java-library`
@@ -9,16 +10,10 @@ plugins {
910
}
1011

1112
dependencies {
12-
errorprone(dependencyFromLibs("errorProne-core"))
13+
errorprone(dependencyFromLibs("error-prone-contrib"))
14+
errorprone(dependencyFromLibs("error-prone-core"))
1315
errorprone(dependencyFromLibs("nullaway"))
14-
constraints {
15-
errorprone("com.google.guava:guava") {
16-
version {
17-
require("33.4.8-jre")
18-
}
19-
because("Older versions use deprecated methods in sun.misc.Unsafe")
20-
}
21-
}
16+
errorprone(dependencyFromLibs("refaster-runner"))
2217
}
2318

2419
nullaway {
@@ -27,43 +22,49 @@ nullaway {
2722

2823
tasks.withType<JavaCompile>().configureEach {
2924
options.errorprone {
30-
val shouldDisableErrorProne = java.toolchain.implementation.orNull == JvmImplementation.J9
31-
if (name == "compileJava" && !shouldDisableErrorProne) {
25+
disableWarningsInGeneratedCode = true
26+
disableAllChecks = !(name == "compileJava" && java.toolchain.implementation.orNull != JvmImplementation.J9)
27+
if (!disableAllChecks.get()) {
28+
errorproneArgs.add("-XepOpt:Refaster:NamePattern=^(?!.*Rules\\$).*") // currently failing Refaster; might consider whitelist.
3229
disable(
33-
34-
// This check is opinionated wrt. which method names it considers unsuitable for import which includes
35-
// a few of our own methods in `ReflectionUtils` etc.
36-
"BadImport",
37-
38-
// The findings of this check are subjective because a named constant can be more readable in many cases
39-
"UnnecessaryLambda",
40-
41-
// Resolving findings for these checks requires ErrorProne's annotations which we don't want to use
42-
"AnnotateFormatMethod",
30+
"AnnotateFormatMethod", // We don`t want to use ErrorProne`s annotations.
31+
"BadImport", // This check is opinionated wrt. which method names it considers unsuitable for import which includes a few of our own methods in `ReflectionUtils` etc.
32+
"DirectReturn", // https://github.com/junit-team/junit-framework/pull/5006#discussion_r2403984446
4333
"DoNotCallSuggester",
44-
"InlineMeSuggester",
4534
"ImmutableEnumChecker",
46-
47-
// Resolving findings for this check requires using Guava which we don't want to use
48-
"StringSplitter",
49-
50-
// Produces a lot of findings that we consider to be false positives, for example for package-private
51-
// classes and methods
52-
"MissingSummary",
35+
"InlineMeSuggester",
36+
"MissingSummary", // Produces a lot of findings that we consider to be false positives, for example for package-private classes and methods.
37+
"StringSplitter", // We don`t want to use Guava.
38+
"UnnecessaryLambda", // The findings of this check are subjective because a named constant can be more readable in many cases.
39+
// picnic
40+
"ConstantNaming",
41+
"FormatStringConcatenation",
42+
"IdentityConversion",
43+
"LexicographicalAnnotationAttributeListing",
44+
"LexicographicalAnnotationListing",
45+
"MissingTestCall",
46+
"NestedOptionals",
47+
"NonStaticImport",
48+
"OptionalOrElseGet",
49+
"PrimitiveComparison",
50+
"TimeZoneUsage",
5351
)
54-
error("PackageLocation")
55-
} else {
56-
disableAllChecks = true
52+
error(
53+
"PackageLocation",
54+
"StaticImport"
55+
)
56+
// fix & introduce new checks with:
57+
// errorproneArgs.addAll("-XepPatchLocation:IN_PLACE","-XepPatchChecks:StaticImport")
5758
}
5859
nullaway {
59-
if (shouldDisableErrorProne) {
60+
if (disableAllChecks.get()) {
6061
disable()
6162
} else {
6263
enable()
6364
}
64-
isJSpecifyMode = true
65-
customContractAnnotations.add("org.junit.platform.commons.annotation.Contract")
6665
checkContracts = true
66+
customContractAnnotations.add("org.junit.platform.commons.annotation.Contract")
67+
isJSpecifyMode = true
6768
suppressionNameAliases.add("DataFlowIssue")
6869
}
6970
}

junit-jupiter-api/src/main/java/org/junit/jupiter/api/ClassOrderer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010

1111
package org.junit.jupiter.api;
1212

13+
import static java.util.Collections.shuffle;
14+
import static java.util.Comparator.comparing;
1315
import static java.util.Comparator.comparingInt;
1416
import static org.apiguardian.api.API.Status.EXPERIMENTAL;
1517
import static org.apiguardian.api.API.Status.STABLE;
1618

17-
import java.util.Collections;
1819
import java.util.Comparator;
1920

2021
import org.apiguardian.api.API;
@@ -148,7 +149,7 @@ public void orderClasses(ClassOrdererContext context) {
148149
context.getClassDescriptors().sort(comparator);
149150
}
150151

151-
private static final Comparator<ClassDescriptor> comparator = Comparator.comparing(
152+
private static final Comparator<ClassDescriptor> comparator = comparing(
152153
descriptor -> descriptor.getTestClass().getName());
153154
}
154155

@@ -171,8 +172,7 @@ public void orderClasses(ClassOrdererContext context) {
171172
context.getClassDescriptors().sort(comparator);
172173
}
173174

174-
private static final Comparator<ClassDescriptor> comparator = Comparator.comparing(
175-
ClassDescriptor::getDisplayName);
175+
private static final Comparator<ClassDescriptor> comparator = comparing(ClassDescriptor::getDisplayName);
176176
}
177177

178178
/**
@@ -265,7 +265,7 @@ public Random() {
265265
*/
266266
@Override
267267
public void orderClasses(ClassOrdererContext context) {
268-
Collections.shuffle(context.getClassDescriptors(),
268+
shuffle(context.getClassDescriptors(),
269269
new java.util.Random(RandomOrdererUtils.getSeed(context::getConfigurationParameter, logger)));
270270
}
271271
}

junit-jupiter-api/src/main/java/org/junit/jupiter/api/MethodOrderer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010

1111
package org.junit.jupiter.api;
1212

13+
import static java.util.Collections.shuffle;
14+
import static java.util.Comparator.comparing;
1315
import static java.util.Comparator.comparingInt;
1416
import static org.apiguardian.api.API.Status.EXPERIMENTAL;
1517
import static org.apiguardian.api.API.Status.STABLE;
1618

1719
import java.lang.reflect.Method;
18-
import java.util.Collections;
1920
import java.util.Comparator;
2021
import java.util.Optional;
2122

@@ -214,8 +215,7 @@ public void orderMethods(MethodOrdererContext context) {
214215
context.getMethodDescriptors().sort(comparator);
215216
}
216217

217-
private static final Comparator<MethodDescriptor> comparator = Comparator.comparing(
218-
MethodDescriptor::getDisplayName);
218+
private static final Comparator<MethodDescriptor> comparator = comparing(MethodDescriptor::getDisplayName);
219219
}
220220

221221
/**
@@ -308,7 +308,7 @@ public Random() {
308308
*/
309309
@Override
310310
public void orderMethods(MethodOrdererContext context) {
311-
Collections.shuffle(context.getMethodDescriptors(),
311+
shuffle(context.getMethodDescriptors(),
312312
new java.util.Random(RandomOrdererUtils.getSeed(context::getConfigurationParameter, logger)));
313313
}
314314

junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/TestInstancePreDestroyCallback.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
package org.junit.jupiter.api.extension;
1212

13+
import static java.util.Collections.reverse;
1314
import static org.apiguardian.api.API.Status.STABLE;
1415

1516
import java.util.ArrayList;
16-
import java.util.Collections;
1717
import java.util.List;
1818
import java.util.Optional;
1919
import java.util.function.Consumer;
@@ -114,7 +114,7 @@ static void preDestroyTestInstances(ExtensionContext context, Consumer<Object> c
114114
current.get().getTestInstances().map(TestInstances::getAllInstances).ifPresent(
115115
destroyedInstances::removeAll);
116116
}
117-
Collections.reverse(destroyedInstances);
117+
reverse(destroyedInstances);
118118
destroyedInstances.forEach(callback);
119119
}
120120

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/ClassBasedTestDescriptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
package org.junit.jupiter.engine.descriptor;
1212

13+
import static java.util.Collections.reverse;
1314
import static java.util.Objects.requireNonNull;
1415
import static java.util.stream.Collectors.joining;
1516
import static org.apiguardian.api.API.Status.INTERNAL;
@@ -30,7 +31,6 @@
3031
import java.lang.reflect.Constructor;
3132
import java.lang.reflect.Method;
3233
import java.util.ArrayList;
33-
import java.util.Collections;
3434
import java.util.List;
3535
import java.util.Optional;
3636
import java.util.Set;
@@ -516,7 +516,7 @@ private void registerAfterEachMethodAdapters(ExtensionRegistrar registrar) {
516516
// synthesized AfterEachMethodAdapters are executed within TestMethodTestDescriptor,
517517
// we have to reverse the afterEachMethods list to put them in top-down order before
518518
// we register them as synthesized extensions.
519-
Collections.reverse(afterEachMethods);
519+
reverse(afterEachMethods);
520520

521521
registerMethodsAsExtensions(afterEachMethods, registrar, this::synthesizeAfterEachMethodAdapter);
522522
}

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/ExtensionUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
package org.junit.jupiter.engine.descriptor;
1212

13+
import static java.util.Comparator.comparingInt;
1314
import static java.util.stream.Collectors.toList;
1415
import static org.junit.platform.commons.support.AnnotationSupport.findAnnotation;
1516
import static org.junit.platform.commons.support.AnnotationSupport.isAnnotated;
@@ -226,7 +227,7 @@ private static Stream<Class<? extends Extension>> streamDeclarativeExtensionType
226227
* @since 5.4
227228
*/
228229
private static final Comparator<Field> orderComparator = //
229-
Comparator.comparingInt(ExtensionUtils::getOrder);
230+
comparingInt(ExtensionUtils::getOrder);
230231

231232
/**
232233
* @since 5.4

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/JupiterTestDescriptor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
package org.junit.jupiter.engine.descriptor;
1212

1313
import static java.util.Collections.emptySet;
14+
import static java.util.Collections.reverse;
1415
import static java.util.stream.Collectors.collectingAndThen;
1516
import static java.util.stream.Collectors.toCollection;
1617
import static java.util.stream.Collectors.toSet;
@@ -108,7 +109,7 @@ <E extends Extension> void invokeExecutionExceptionHandlers(Class<E> handlerType
108109
Throwable throwable, ExceptionHandlerInvoker<E> handlerInvoker) {
109110

110111
List<E> extensions = registry.getExtensions(handlerType);
111-
Collections.reverse(extensions);
112+
reverse(extensions);
112113
invokeExecutionExceptionHandlers(extensions, throwable, handlerInvoker);
113114
}
114115

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/execution/DefaultTestInstances.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
package org.junit.jupiter.engine.execution;
1212

13+
import static java.util.Collections.unmodifiableList;
1314
import static org.apiguardian.api.API.Status.INTERNAL;
1415

1516
import java.util.ArrayList;
16-
import java.util.Collections;
1717
import java.util.List;
1818
import java.util.ListIterator;
1919
import java.util.Optional;
@@ -32,7 +32,7 @@ public static DefaultTestInstances of(Object instance) {
3232
public static DefaultTestInstances of(TestInstances testInstances, Object instance) {
3333
List<Object> allInstances = new ArrayList<>(testInstances.getAllInstances());
3434
allInstances.add(instance);
35-
return new DefaultTestInstances(Collections.unmodifiableList(allInstances));
35+
return new DefaultTestInstances(unmodifiableList(allInstances));
3636
}
3737

3838
private final List<Object> instances;

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/PreInterruptThreadDumpPrinter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void beforeThreadInterrupt(PreInterruptContext preInterruptContext, Exten
4949
sb.append(NL);
5050
// Use the same prefix as java.lang.Throwable.printStackTrace(PrintStreamOrWriter)
5151
sb.append("\tat ");
52-
sb.append(stackTraceElement.toString());
52+
sb.append(stackTraceElement);
5353
}
5454
sb.append(NL);
5555
}

0 commit comments

Comments
 (0)