Skip to content

Commit

Permalink
clean up errorprone exclusions (gradle#28882)
Browse files Browse the repository at this point in the history
  • Loading branch information
blindpirate authored Apr 23, 2024
2 parents 5771ba6 + 8106d7c commit 30662f2
Show file tree
Hide file tree
Showing 32 changed files with 51 additions and 76 deletions.
2 changes: 0 additions & 2 deletions platforms/core-configuration/model-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ errorprone {
"StringCaseLocaleUsage", // 13 occurrences
"TypeParameterShadowing", // 2 occurrences
"UndefinedEquals", // 2 occurrences
"UnnecessaryLambda", // 1 occurrences
"UnnecessaryParentheses", // 1 occurrences
"UnnecessaryStringBuilder", // 1 occurrences
"UnusedMethod", // 8 occurrences
"UnusedTypeParameter", // 1 occurrences
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class NamedObjectInstantiator implements ManagedFactory {
private final CrossBuildInMemoryCache<Class<?>, LoadingCache<String, Object>> generatedTypes;
private final String implSuffix;
private final String factorySuffix;
private final Function<Class<?>, LoadingCache<String, Object>> cacheFactory = type -> CacheBuilder.newBuilder().build(loaderFor(type));
private final Function<Class<?>, LoadingCache<String, Object>> cacheFactoryFunction = this::cacheFactory;

public NamedObjectInstantiator(CrossBuildInMemoryCacheFactory cacheFactory) {
implSuffix = ClassGeneratorSuffixRegistry.assign("$Impl");
Expand All @@ -98,7 +98,7 @@ public <T> T fromState(Class<T> type, Object state) {

public <T extends Named> T named(final Class<T> type, final String name) throws ObjectInstantiationException {
try {
return type.cast(generatedTypes.get(type, cacheFactory).getUnchecked(name));
return type.cast(generatedTypes.get(type, cacheFactoryFunction).getUnchecked(name));
} catch (UncheckedExecutionException e) {
throw new ObjectInstantiationException(type, e.getCause());
} catch (Exception e) {
Expand Down Expand Up @@ -282,6 +282,10 @@ private void visitFields(Class<?> type, ValidationProblemCollector collector) {
}
}

private LoadingCache<String, Object> cacheFactory(Class<?> type) {
return CacheBuilder.newBuilder().build(loaderFor(type));
}

protected abstract static class ClassGeneratingLoader extends CacheLoader<String, Object> {
@Override
public abstract Object load(String name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ public boolean isAchieved() {
return false;
}
for (ModelNodeInternal child : node.getLinks()) {
if (child.isAtLeast(Discovered) && (child.getPromise().canBeViewedAs(typeToBind))) {
if (child.isAtLeast(Discovered) && child.getPromise().canBeViewedAs(typeToBind)) {
return true;
}
}
Expand Down
6 changes: 0 additions & 6 deletions platforms/core-configuration/model-groovy/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ plugins {

description = "Groovy specific adaptations to the model management."

errorprone {
disabledChecks.addAll(
"UnnecessaryParentheses", // 1 occurrences
)
}

dependencies {
api(project(":base-services"))
api(project(":model-core"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void visitRuleClosure(ClosureExpression expression, Expression invocation
VariableExpression parentInputsVariable = inputsVariable;
try {
inputs = new InputReferences();
inputsVariable = new VariableExpression("__rule_inputs_var_" + (counter++), POTENTIAL_INPUTS);
inputsVariable = new VariableExpression("__rule_inputs_var_" + counter++, POTENTIAL_INPUTS);
inputsVariable.setClosureSharedVariable(true);
super.visitClosureExpression(expression);
BlockStatement code = (BlockStatement) expression.getCode();
Expand Down
1 change: 0 additions & 1 deletion platforms/core-runtime/base-services/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ errorprone {
"ThreadLocalUsage", // 4 occurrences
"TypeParameterUnusedInFormals", // 5 occurrences
"URLEqualsHashCode", // 1 occurrences
"UnnecessaryParentheses", // 2 occurrences
"UnsynchronizedOverridesSynchronized", // 2 occurrences
"UnusedMethod", // 2 occurrences
"UnusedVariable", // 3 occurrences
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ public static <T extends Collection<?>> T flatten(Collection<?> elements, T addT
flatten((Collection<?>) element, addTo, flattenMaps, flattenArrays);
} else if ((element instanceof Map) && flattenMaps) {
flatten(((Map<?, ?>) element).values(), addTo, flattenMaps, flattenArrays);
} else if ((element.getClass().isArray()) && flattenArrays) {
} else if (element.getClass().isArray() && flattenArrays) {
flatten(asList((Object[]) element), addTo, flattenMaps, flattenArrays);
} else {
(Cast.<Collection<Object>>uncheckedNonnullCast(addTo)).add(element);
Cast.<Collection<Object>>uncheckedNonnullCast(addTo).add(element);
}
}
return addTo;
Expand Down
1 change: 0 additions & 1 deletion platforms/core-runtime/build-profile/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ errorprone {
disabledChecks.addAll(
"DateFormatConstant", // 2 occurrences
"ThreadLocalUsage", // 1 occurrences
"UnnecessaryParentheses", // 1 occurrences
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public String getPath() {
}

public String getStatus() {
return state.getSkipped() ? state.getSkipMessage() : (state.getDidWork()) ? "" : NO_WORK_MESSAGE;
return state.getSkipped() ? state.getSkipMessage() : state.getDidWork() ? "" : NO_WORK_MESSAGE;
}

public TaskState getState() {
Expand Down
6 changes: 0 additions & 6 deletions platforms/core-runtime/functional/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ plugins {

description = "Tools to work with functional code, including data structures"

errorprone {
disabledChecks.addAll(
"UnnecessaryLambda", // 1 occurrences
)
}

dependencies {
api(libs.jsr305)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@
* Promote to a more shared subproject if useful.
*/
public abstract class Combiners {
private static final BinaryOperator<?> NON_COMBINING = (a, b) -> {
throw new IllegalStateException("Not a combinable operation");
};

/**
* We know the stream we are processing is handled sequentially, and hence there is no need for a combiner.
*/
@SuppressWarnings("unchecked")
public static <T> BinaryOperator<T> nonCombining() {
return (BinaryOperator<T>) NON_COMBINING;
return Combiners::unsupportedCombineOperation;
}

private static <T> T unsupportedCombineOperation(T a, T b) {
throw new IllegalStateException("Not a combinable operation");
}
}
1 change: 0 additions & 1 deletion platforms/core-runtime/logging/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ errorprone {
"StringSplitter", // 4 occurrences
"ThreadLocalUsage", // 1 occurrences
"TypeParameterUnusedInFormals", // 1 occurrences
"UnnecessaryParentheses", // 3 occurrences
"UnusedMethod", // 3 occurrences
"UnusedVariable", // 1 occurrences
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ private static class NumberedPrefixer implements Prefixer {

@Override
public String nextPrefix() {
return " " + (++cur) + ". ";
return " " + ++cur + ". ";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ public static <T extends Collection<?>> T flatten(Collection<?> elements, T addT
flatten((Collection<?>) element, addTo, flattenMaps, flattenArrays);
} else if ((element instanceof Map) && flattenMaps) {
flatten(((Map<?, ?>) element).values(), addTo, flattenMaps, flattenArrays);
} else if ((element.getClass().isArray()) && flattenArrays) {
} else if (element.getClass().isArray() && flattenArrays) {
flatten(asList((Object[]) element), addTo, flattenMaps, flattenArrays);
} else {
(Cast.<Collection<Object>>uncheckedNonnullCast(addTo)).add(element);
Cast.<Collection<Object>>uncheckedNonnullCast(addTo).add(element);
}
}
return addTo;
Expand Down
1 change: 0 additions & 1 deletion platforms/core-runtime/messaging/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ errorprone {
"ReferenceEquality", // 1 occurrences
"StringCaseLocaleUsage", // 1 occurrences
"ThreadPriorityCheck", // 1 occurrences
"UnnecessaryParentheses", // 2 occurrences
"UnrecognisedJavadocTag", // 1 occurrences
)
}
Expand Down
1 change: 0 additions & 1 deletion platforms/ide/ide-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ errorprone {
disabledChecks.addAll(
"MixedMutabilityReturnType", // 2 occurrences
"ShortCircuitBoolean", // 2 occurrences
"UnnecessaryParentheses", // 1 occurrences
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private void declareUniqueProjectLibraries(Set<ProjectLibrary> projectLibraries)
String originalName = newLibrary.getName();
int suffix = 1;
while (containsLibraryWithSameName(existingLibraries, newLibrary.getName())) {
newLibrary.setName(originalName + "-" + (suffix++));
newLibrary.setName(originalName + "-" + suffix++);
}
existingLibraries.add(newLibrary);
}
Expand Down
1 change: 0 additions & 1 deletion platforms/jvm/jacoco/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ description = "Plugin and integration with JaCoCo code coverage"
errorprone {
disabledChecks.addAll(
"ReferenceEquality", // 3 occurrences
"UnnecessaryParentheses", // 1 occurrences
"UnusedMethod", // 1 occurrences
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public ArgumentAppender(StringBuilder builder, File workingDirectory) {
public void append(String name, @Nullable Object value) {
if (value != null
&& !((value instanceof Collection) && ((Collection) value).isEmpty())
&& !((value instanceof String) && (StringUtils.isEmpty((String) value)))
&& !((value instanceof String) && StringUtils.isEmpty((String) value))
&& !((value instanceof Integer) && ((Integer) value == 0))) {
if (anyArgs) {
builder.append(',');
Expand Down
1 change: 0 additions & 1 deletion platforms/jvm/language-groovy/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ description = "Adds support for building Groovy projects"
errorprone {
disabledChecks.addAll(
"ModifyCollectionInEnhancedForLoop", // 1 occurrences
"UnnecessaryParentheses", // 1 occurrences
"UnusedMethod", // 4 occurrences
"UnusedVariable", // 1 occurrences
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private WorkResult delegateAndHandleErrors(GroovyJavaJointCompileSpec spec) {
// in-process Groovy compilation throws a CompilationFailedException from another classloader, hence testing class name equality
// TODO:pm Prefer class over class name for equality check once using WorkerExecutor for in-process groovy compilation
if ((spec.getCompileOptions().isFailOnError() && spec.getGroovyCompileOptions().isFailOnError())
|| (!CompilationFailedException.class.getName().equals(e.getClass().getName()))) {
|| !CompilationFailedException.class.getName().equals(e.getClass().getName())) {
throw e;
}
LOGGER.debug("Ignoring compilation failure.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import java.util.function.Predicate;

@SuppressWarnings("UnnecessaryLambda")
public class JvmInstallationMetadataMatcher implements Predicate<JvmInstallationMetadata> {
private final JavaLanguageVersion languageVersion;
private final DefaultJvmVendorSpec vendorSpec;
Expand All @@ -43,7 +42,7 @@ public JvmInstallationMetadataMatcher(JavaToolchainSpec spec) {

@Override
public boolean test(JvmInstallationMetadata metadata) {
Predicate<JvmInstallationMetadata> predicate = languagePredicate().and(vendorPredicate()).and(implementationPredicate());
Predicate<JvmInstallationMetadata> predicate = languagePredicate().and(vendorPredicate()).and(this::implementationTest);
return predicate.test(metadata);
}

Expand All @@ -54,18 +53,6 @@ private Predicate<JvmInstallationMetadata> languagePredicate() {
};
}

private Predicate<? super JvmInstallationMetadata> implementationPredicate() {
return metadata -> {
if (jvmImplementation == JvmImplementation.VENDOR_SPECIFIC) {
return true;
}

final boolean j9Requested = isJ9ExplicitlyRequested() || isJ9RequestedViaVendor();
final boolean isJ9Vm = metadata.hasCapability(JvmInstallationMetadata.JavaInstallationCapability.J9_VIRTUAL_MACHINE);
return j9Requested == isJ9Vm;
};
}

private boolean isJ9ExplicitlyRequested() {
return jvmImplementation == JvmImplementation.J9;
}
Expand All @@ -78,4 +65,13 @@ private Predicate<JvmInstallationMetadata> vendorPredicate() {
return vendorSpec;
}

private boolean implementationTest(JvmInstallationMetadata metadata) {
if (jvmImplementation == JvmImplementation.VENDOR_SPECIFIC) {
return true;
}

final boolean j9Requested = isJ9ExplicitlyRequested() || isJ9RequestedViaVendor();
final boolean isJ9Vm = metadata.hasCapability(JvmInstallationMetadata.JavaInstallationCapability.J9_VIRTUAL_MACHINE);
return j9Requested == isJ9Vm;
}
}
1 change: 0 additions & 1 deletion platforms/jvm/toolchains-jvm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ description = "Adds support for using JVM toolchains in projects"
errorprone {
disabledChecks.addAll(
"StringCaseLocaleUsage", // 2 occurrences
"UnnecessaryLambda", // 2 occurrences
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static org.gradle.api.internal.lambdas.SerializableLambdas.spec;
Expand Down Expand Up @@ -76,16 +75,16 @@ private void printOptions(StyledTextOutput output) {
output.println();
}

private List<JvmToolchainMetadata> invalidToolchains(List<JvmToolchainMetadata> toolchains) {
return toolchains.stream().filter(t -> !isValidToolchain().test(t)).collect(Collectors.toList());
private static List<JvmToolchainMetadata> invalidToolchains(List<JvmToolchainMetadata> toolchains) {
return toolchains.stream().filter(t -> !isValidToolchain(t)).collect(Collectors.toList());
}

private List<JvmToolchainMetadata> validToolchains(Collection<JvmToolchainMetadata> toolchains) {
return toolchains.stream().filter(isValidToolchain()).sorted(TOOLCHAIN_COMPARATOR).collect(Collectors.toList());
private static List<JvmToolchainMetadata> validToolchains(Collection<JvmToolchainMetadata> toolchains) {
return toolchains.stream().filter(ShowToolchainsTask::isValidToolchain).sorted(TOOLCHAIN_COMPARATOR).collect(Collectors.toList());
}

private Predicate<? super JvmToolchainMetadata> isValidToolchain() {
return t -> t.metadata.isValidInstallation();
private static boolean isValidToolchain(JvmToolchainMetadata t) {
return t.metadata.isValidInstallation();
}

private List<JvmToolchainMetadata> allReportableToolchains() {
Expand Down
1 change: 0 additions & 1 deletion platforms/native/platform-native/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ errorprone {
"StringCaseLocaleUsage", // 3 occurrences
"StringCharset", // 2 occurrences
"StringSplitter", // 1 occurrences
"UnnecessaryParentheses", // 1 occurrences
"UnnecessaryTypeArgument", // 2 occurrences
"UnusedMethod", // 11 occurrences
"UnusedTypeParameter", // 1 occurrences
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private void deletePreviousOutput(StaticLibraryArchiverSpec spec) {
if (!spec.getOutputFile().isFile()) {
return;
}
if (!(spec.getOutputFile().delete())) {
if (!spec.getOutputFile().delete()) {
throw new GradleException("Create static archive failed: could not delete previous archive");
}
}
Expand Down
2 changes: 0 additions & 2 deletions subprojects/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ errorprone {
"TypeParameterShadowing", // 1 occurrences
"TypeParameterUnusedInFormals", // 2 occurrences
"UndefinedEquals", // 1 occurrences
"UnnecessaryLambda", // 1 occurrences
"UnnecessaryParentheses", // 1 occurrences
"UnrecognisedJavadocTag", // 1 occurrences
"UnusedMethod", // 18 occurrences
"UnusedVariable", // 8 occurrences
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Iterator<T> iterator() {
for (T propertySpec : properties) {
String propertyName = propertySpec.getPropertyName();
if (propertyName == null) {
propertyName = "$" + (++unnamedPropertyCounter);
propertyName = "$" + ++unnamedPropertyCounter;
propertySpec.withPropertyName(propertyName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static ExternalModuleDependency module(Dependencies self, Map<String, Cha

@Nullable
private static String extract(Map<String, CharSequence> map, String key) {
return (map.containsKey(key)) ? map.get(key).toString() : null;
return map.containsKey(key) ? map.get(key).toString() : null;
}

/**
Expand Down
Loading

0 comments on commit 30662f2

Please sign in to comment.