Skip to content

Commit 09fc8a9

Browse files
author
Vincent Potucek
committed
Add error-prone.picnic.tech/bugpatterns/NonStaticImport
- https://error-prone.picnic.tech/bugpatterns/StaticImport Signed-off-by: Vincent Potucek <vpotucek@me.com>
1 parent dbbacd6 commit 09fc8a9

File tree

5 files changed

+32
-30
lines changed

5 files changed

+32
-30
lines changed

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

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import junitbuild.extensions.dependencyFromLibs
22
import net.ltgt.gradle.errorprone.errorprone
33
import net.ltgt.gradle.nullaway.nullaway
4+
import org.gradle.jvm.toolchain.JvmImplementation.J9
5+
import java.lang.System.getenv
46

57
plugins {
68
`java-library`
@@ -16,27 +18,19 @@ dependencies {
1618

1719
tasks.withType<JavaCompile>().configureEach {
1820
options.errorprone {
19-
val shouldDisableErrorProne = java.toolchain.implementation.orNull == JvmImplementation.J9
20-
if (name == "compileJava" && !shouldDisableErrorProne) {
21-
disable(
22-
"AnnotateFormatMethod", // We don`t want to use ErrorProne's annotations.
23-
"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.
24-
"DoNotCallSuggester", // We don`t want to use ErrorProne's annotations.
25-
"ImmutableEnumChecker", // We don`t want to use ErrorProne's annotations.
26-
"InlineMeSuggester", // We don`t want to use ErrorProne's annotations.
27-
"MissingSummary", // Produces a lot of findings that we consider to be false positives, for example for package-private classes and methods.
28-
"StringSplitter", // We don`t want to use Guava.
29-
"UnnecessaryLambda", // The findings of this check are subjective because a named constant can be more readable in many cases.
21+
val enableErrorProne = java.toolchain.implementation.orNull != J9
22+
if (enableErrorProne && name == "compileJava") {
23+
disableAllWarnings = true // considering this immense spam burden, remove this once to fix dedicated flaw. https://github.com/diffplug/spotless/pull/2766
24+
disable( // We don`t want to use ErrorProne's annotations.
3025
// picnic (https://error-prone.picnic.tech)
3126
"ConstantNaming",
32-
"DirectReturn", // We don`t want to use this: https://github.com/junit-team/junit-framework/pull/5006#discussion_r2403984446
27+
"DirectReturn", // We don`t want to use this. https://github.com/junit-team/junit-framework/pull/5006#discussion_r2403984446
3328
"FormatStringConcatenation",
3429
"IdentityConversion",
35-
"LexicographicalAnnotationAttributeListing", // We don`t want to use this: https://github.com/junit-team/junit-framework/pull/5043#pullrequestreview-3330615838
30+
"LexicographicalAnnotationAttributeListing", // We don`t want to use this. https://github.com/junit-team/junit-framework/pull/5043#pullrequestreview-3330615838
3631
"LexicographicalAnnotationListing",
3732
"MissingTestCall",
3833
"NestedOptionals",
39-
"NonStaticImport",
4034
"OptionalOrElseGet",
4135
"PrimitiveComparison",
4236
"StaticImport",
@@ -45,22 +39,34 @@ tasks.withType<JavaCompile>().configureEach {
4539
error(
4640
"CanonicalAnnotationSyntax",
4741
"IsInstanceLambdaUsage",
42+
"MissingOverride",
43+
"NonStaticImport",
4844
"PackageLocation",
4945
"RedundantStringConversion",
5046
"RedundantStringEscape",
47+
"SelfAssignment",
48+
"StringCharset",
49+
"StringJoin",
5150
)
51+
if (!getenv().containsKey("CI") && getenv("IN_PLACE").toBoolean()) {
52+
errorproneArgs.addAll(
53+
"-XepPatchLocation:IN_PLACE",
54+
"-XepPatchChecks:" +
55+
"NonStaticImport,"
56+
)
57+
}
5258
} else {
5359
disableAllChecks = true
5460
}
5561
nullaway {
56-
if (shouldDisableErrorProne) {
57-
disable()
58-
} else {
62+
if (enableErrorProne) {
5963
enable()
64+
} else {
65+
disable()
6066
}
61-
onlyNullMarked = true
62-
isJSpecifyMode = true
6367
checkContracts = true
68+
isJSpecifyMode = true
69+
onlyNullMarked = true
6470
suppressionNameAliases.add("DataFlowIssue")
6571
}
6672
}

junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/EmptyArgumentsProvider.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
package org.junit.jupiter.params.provider;
1212

1313
import static org.junit.jupiter.params.provider.Arguments.arguments;
14-
import static org.junit.platform.commons.util.ReflectionUtils.newInstance;
1514

1615
import java.lang.reflect.Array;
1716
import java.lang.reflect.Constructor;
@@ -26,12 +25,12 @@
2625
import java.util.SortedMap;
2726
import java.util.SortedSet;
2827
import java.util.stream.Stream;
29-
3028
import org.junit.jupiter.api.extension.ExtensionContext;
3129
import org.junit.jupiter.params.support.ParameterDeclaration;
3230
import org.junit.jupiter.params.support.ParameterDeclarations;
3331
import org.junit.platform.commons.PreconditionViolationException;
3432
import org.junit.platform.commons.util.Preconditions;
33+
import org.junit.platform.commons.util.ReflectionUtils;
3534

3635
/**
3736
* @since 5.4
@@ -80,7 +79,7 @@ public Stream<? extends Arguments> provideArguments(ParameterDeclarations parame
8079
if (Collection.class.isAssignableFrom(parameterType) || Map.class.isAssignableFrom(parameterType)) {
8180
Optional<Constructor<?>> defaultConstructor = getDefaultConstructor(parameterType);
8281
if (defaultConstructor.isPresent()) {
83-
return Stream.of(arguments(newInstance(defaultConstructor.get())));
82+
return Stream.of(arguments(ReflectionUtils.newInstance(defaultConstructor.get())));
8483
}
8584
}
8685
if (parameterType.isArray()) {

junit-platform-commons/src/main/java/org/junit/platform/commons/support/conversion/FallbackStringToObjectConverter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import static org.junit.platform.commons.support.ReflectionSupport.findMethods;
1717
import static org.junit.platform.commons.support.ReflectionSupport.invokeMethod;
1818
import static org.junit.platform.commons.util.ReflectionUtils.findConstructors;
19-
import static org.junit.platform.commons.util.ReflectionUtils.newInstance;
2019

2120
import java.lang.reflect.Constructor;
2221
import java.lang.reflect.Executable;
@@ -25,9 +24,9 @@
2524
import java.util.concurrent.ConcurrentHashMap;
2625
import java.util.function.Function;
2726
import java.util.function.Predicate;
28-
2927
import org.jspecify.annotations.Nullable;
3028
import org.junit.platform.commons.util.Preconditions;
29+
import org.junit.platform.commons.util.ReflectionUtils;
3130

3231
/**
3332
* {@code FallbackStringToObjectConverter} is a {@link StringToObjectConverter}
@@ -115,7 +114,7 @@ public boolean canConvertTo(Class<?> targetType) {
115114
}
116115
Constructor<?> constructor = findFactoryConstructor(targetType, parameterType);
117116
if (constructor != null) {
118-
return source -> newInstance(constructor, source);
117+
return source -> ReflectionUtils.newInstance(constructor, source);
119118
}
120119
return null;
121120
}

junit-platform-launcher/src/main/java/org/junit/platform/launcher/tagexpression/ShuntingYard.java

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

1111
package org.junit.platform.launcher.tagexpression;
1212

13-
import static java.lang.Integer.MIN_VALUE;
1413
import static java.util.Objects.requireNonNull;
1514
import static org.junit.platform.launcher.tagexpression.Operator.nullaryOperator;
1615
import static org.junit.platform.launcher.tagexpression.ParseStatus.emptyTagExpression;
@@ -34,7 +33,7 @@ class ShuntingYard {
3433

3534
private static final Operator RightParenthesis = nullaryOperator(")", -1);
3635
private static final Operator LeftParenthesis = nullaryOperator("(", -2);
37-
private static final Operator Sentinel = nullaryOperator("sentinel", MIN_VALUE);
36+
private static final Operator Sentinel = nullaryOperator("sentinel", Integer.MIN_VALUE);
3837
private static final Token SentinelToken = new Token(-1, "");
3938

4039
private final Operators validOperators = new Operators();

junit-platform-testkit/src/main/java/org/junit/platform/testkit/engine/Events.java

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

1111
package org.junit.platform.testkit.engine;
1212

13-
import static java.util.Collections.sort;
1413
import static java.util.function.Predicate.isEqual;
1514
import static org.apiguardian.api.API.Status.MAINTAINED;
1615
import static org.junit.platform.commons.util.FunctionUtils.where;
@@ -22,14 +21,14 @@
2221
import java.io.Writer;
2322
import java.util.ArrayList;
2423
import java.util.Arrays;
24+
import java.util.Collections;
2525
import java.util.List;
2626
import java.util.Objects;
2727
import java.util.Optional;
2828
import java.util.function.Consumer;
2929
import java.util.function.Function;
3030
import java.util.function.Predicate;
3131
import java.util.stream.Stream;
32-
3332
import org.apiguardian.api.API;
3433
import org.assertj.core.api.Assertions;
3534
import org.assertj.core.api.Condition;
@@ -457,7 +456,7 @@ private static void assertEventsMatchLooselyInOrder(List<Event> events, Conditio
457456

458457
private static boolean isNotInIncreasingOrder(List<Integer> indices) {
459458
List<Integer> copy = new ArrayList<>(indices);
460-
sort(copy);
459+
Collections.sort(copy);
461460

462461
return !indices.equals(copy);
463462
}

0 commit comments

Comments
 (0)