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

Fix error prone warnings in :core-execution #28819

Merged
merged 29 commits into from May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d95a1e5
Fix ErrorProne warnings in :hashing
lptr Apr 15, 2024
c5e5c50
Fix EmptyBlockTag in :persistent-cache
lptr Apr 15, 2024
b3a8557
Fix LockNotBeforeTry in :persistent-cache
lptr Apr 15, 2024
81e3545
Fix NonAtomicVolatileUpdate in :persistent-cache
lptr Apr 15, 2024
e590e5c
Fix StringCaseLocaleUsage in :persistent-cache
lptr Apr 15, 2024
6727a22
Locally suppress ThreadLocalUsage in :persistent-cache
lptr Apr 15, 2024
496fa76
Fix UnnecessaryLambda in :persistent-cache
lptr Apr 15, 2024
bb763da
Fix UnusedMethod in :persistent-cache
lptr Apr 15, 2024
c19bf59
Fix UnusedVariable in :persistent-cache
lptr Apr 15, 2024
02c2d1b
Suppress WaitNotInLoop locally in :persistent-cache
lptr Apr 15, 2024
9f85c66
Fix AnnotateFormatMethod in :execution
lptr Apr 15, 2024
5507e68
Fix BadImport in :execution
lptr Apr 15, 2024
a540c07
Locally suppress Finally in :execution
lptr Apr 15, 2024
2702922
Use an enum instead of Boolean in DefaultOutputFilesRepository.Output…
lptr Apr 15, 2024
23c1daf
Locally suppress SameNameButDifferent in :execution
lptr Apr 15, 2024
56e18ec
Fix StringCaseLocaleUsage in :execution
lptr Apr 15, 2024
259df69
Fix SuperCallToObjectMethod in :execution
lptr Apr 15, 2024
1f69d72
Fix UndefinedEquals in :execution
lptr Apr 15, 2024
38f5f78
Fix UnusedVariable in :execution
lptr Apr 15, 2024
35ba7fb
Locally ignore ImmutableEnumChecker in :snapshots
lptr Apr 15, 2024
a93e058
Fix LockNotBeforeTry in :snapshots
lptr Apr 15, 2024
0e07ee7
Fix ReferenceEquality in :snapshots
lptr Apr 15, 2024
665fbe7
Ignore "unused" services in :worker-processes
lptr Apr 15, 2024
d04d964
Locally ignore URLEqualsHashCode in :workers
lptr Apr 15, 2024
c51ab4f
Locally ignore "unused" service methods in :workers
lptr Apr 15, 2024
7fb6cdf
Add ErrorProne annotations as compile only
lptr Apr 15, 2024
d3045c9
Improve logging test
lptr Apr 15, 2024
9ffa942
Fix unnecessary lambda
lptr Apr 22, 2024
4064396
Merge remote-tracking branch 'origin/master'
lptr May 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -55,6 +55,7 @@ abstract class ExternalModulesExtension(isBundleGroovy4: Boolean) {
val commonsMath = "org.apache.commons:commons-math3"
val configurationCacheReport = "org.gradle.buildtool.internal:configuration-cache-report:$configurationCacheReportVersion"
val eclipseSisuPlexus = "org.eclipse.sisu:org.eclipse.sisu.plexus"
val errorProneAnnotations = "com.google.errorprone:error_prone_annotations"
val fastutil = "it.unimi.dsi:fastutil"
val gcs = "com.google.apis:google-api-services-storage"
val googleApiClient = "com.google.api-client:google-api-client"
Expand Down
Expand Up @@ -16,10 +16,10 @@

package org.gradle.configurationcache.problems

import org.gradle.internal.problems.failure.Failure
import org.gradle.internal.problems.failure.FailurePrinter
import org.gradle.internal.problems.failure.FailurePrinterListener
import org.gradle.internal.problems.failure.StackTraceRelevance
import org.gradle.internal.problems.failure.Failure


internal
Expand Down
14 changes: 1 addition & 13 deletions platforms/core-execution/execution/build.gradle.kts
Expand Up @@ -4,19 +4,6 @@ plugins {

description = "Execution engine that takes a unit of work and makes it happen"

errorprone {
disabledChecks.addAll(
"AnnotateFormatMethod", // 1 occurrences
"Finally", // 2 occurrences
"ReferenceEquality", // 1 occurrences
"SameNameButDifferent", // 5 occurrences
"StringCaseLocaleUsage", // 8 occurrences
"SuperCallToObjectMethod", // 2 occurrences
"UndefinedEquals", // 1 occurrences
"UnusedVariable", // 1 occurrences
)
}

dependencies {
api(libs.guava)
api(libs.jsr305)
Expand All @@ -25,6 +12,7 @@ dependencies {
api(projects.concurrent)
api(projects.javaLanguageExtensions)
api(projects.serialization)
compileOnly(libs.errorProneAnnotations)
api(project(":base-services"))
api(project(":build-cache"))
api(project(":build-cache-base"))
Expand Down
Expand Up @@ -118,7 +118,6 @@ public ExecutionStateChanges detectChanges(
ImmutableList<String> incrementalInputFileChangeMessages = collectChanges(incrementalInputFileChanges);
return ExecutionStateChanges.incremental(
incrementalInputFileChangeMessages,
thisExecution,
incrementalInputFileChanges,
incrementalInputProperties
);
Expand Down
Expand Up @@ -16,11 +16,14 @@

package org.gradle.internal.execution.history.changes;

import com.google.errorprone.annotations.FormatMethod;

import java.util.Objects;

public class DescriptiveChange implements Change {
private final String message;

@FormatMethod
public DescriptiveChange(String message, Object... params) {
this.message = String.format(message, params);
}
Expand Down
Expand Up @@ -31,11 +31,8 @@ public interface ExecutionStateChanges {

InputChangesInternal createInputChanges();

BeforeExecutionState getBeforeExecutionState();

static ExecutionStateChanges incremental(
ImmutableList<String> changeDescriptions,
BeforeExecutionState beforeExecutionState,
InputFileChanges inputFileChanges,
IncrementalInputProperties incrementalInputProperties
) {
Expand All @@ -49,11 +46,6 @@ public ImmutableList<String> getChangeDescriptions() {
public InputChangesInternal createInputChanges() {
return new IncrementalInputChanges(inputFileChanges, incrementalInputProperties);
}

@Override
public BeforeExecutionState getBeforeExecutionState() {
return beforeExecutionState;
}
};
}

Expand All @@ -72,11 +64,6 @@ public ImmutableList<String> getChangeDescriptions() {
public InputChangesInternal createInputChanges() {
return new NonIncrementalInputChanges(beforeExecutionState.getInputFileProperties(), incrementalInputProperties);
}

@Override
public BeforeExecutionState getBeforeExecutionState() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I love how code evaporates

return beforeExecutionState;
}
};
}
}
Expand Up @@ -16,9 +16,9 @@

package org.gradle.internal.execution.history.impl;

import org.gradle.cache.IndexedCache;
import org.gradle.cache.IndexedCacheParameters;
import org.gradle.cache.PersistentCache;
import org.gradle.cache.IndexedCache;
import org.gradle.cache.internal.InMemoryCacheDecoratorFactory;
import org.gradle.internal.execution.history.OutputFilesRepository;
import org.gradle.internal.snapshot.DirectorySnapshot;
Expand All @@ -35,7 +35,11 @@
public class DefaultOutputFilesRepository implements OutputFilesRepository, Closeable {

private final PersistentCache cacheAccess;
private final IndexedCache<String, Boolean> outputFiles; // The value is true if it is an output file, false if it is a parent of an output file
enum OutputKind {
OUTPUT,
PARENT_OF_OUTPUT
}
private final IndexedCache<String, OutputKind> outputFiles;

public DefaultOutputFilesRepository(PersistentCache cacheAccess, InMemoryCacheDecoratorFactory inMemoryCacheDecoratorFactory) {
this.cacheAccess = cacheAccess;
Expand All @@ -51,7 +55,7 @@ public boolean isGeneratedByGradle(File file) {
private boolean isContainedInAnOutput(File absoluteFile) {
File currentFile = absoluteFile;
while (currentFile != null) {
if (outputFiles.getIfPresent(currentFile.getPath()) == Boolean.TRUE) {
if (outputFiles.getIfPresent(currentFile.getPath()) == OutputKind.OUTPUT) {
return true;
}
currentFile = currentFile.getParentFile();
Expand Down Expand Up @@ -81,14 +85,14 @@ public void visitRegularFile(RegularFileSnapshot fileSnapshot) {
private void recordOutputSnapshot(FileSystemLocationSnapshot snapshot) {
String outputPath = snapshot.getAbsolutePath();
File outputFile = new File(outputPath);
outputFiles.put(outputPath, Boolean.TRUE);
outputFiles.put(outputPath, OutputKind.OUTPUT);
File outputFileParent = outputFile.getParentFile();
while (outputFileParent != null) {
String parentPath = outputFileParent.getPath();
if (outputFiles.getIfPresent(parentPath) != null) {
break;
}
outputFiles.put(parentPath, Boolean.FALSE);
outputFiles.put(parentPath, OutputKind.PARENT_OF_OUTPUT);
outputFileParent = outputFileParent.getParentFile();
}
}
Expand All @@ -98,8 +102,8 @@ private void recordOutputSnapshot(FileSystemLocationSnapshot snapshot) {
}
}

private static IndexedCacheParameters<String, Boolean> cacheParameters(InMemoryCacheDecoratorFactory inMemoryCacheDecoratorFactory) {
return IndexedCacheParameters.of("outputFiles", String.class, Boolean.class)
private static IndexedCacheParameters<String, OutputKind> cacheParameters(InMemoryCacheDecoratorFactory inMemoryCacheDecoratorFactory) {
return IndexedCacheParameters.of("outputFiles", String.class, OutputKind.class)
.withCacheDecorator(inMemoryCacheDecoratorFactory.decorator(100000, true));
}

Expand Down
Expand Up @@ -16,7 +16,6 @@

package org.gradle.internal.execution.history.impl;

import com.google.common.base.Objects;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Interner;
import org.gradle.internal.fingerprint.FileCollectionFingerprint;
Expand Down Expand Up @@ -85,18 +84,22 @@ private void writeRootHashes(Encoder encoder, ImmutableMultimap<String, HashCode
}

@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

FileCollectionFingerprintSerializer rhs = (FileCollectionFingerprintSerializer) obj;
return Objects.equal(fingerprintMapSerializer, rhs.fingerprintMapSerializer)
&& Objects.equal(hashCodeSerializer, rhs.hashCodeSerializer);
FileCollectionFingerprintSerializer that = (FileCollectionFingerprintSerializer) o;
return fingerprintMapSerializer.equals(that.fingerprintMapSerializer) && hashCodeSerializer.equals(that.hashCodeSerializer);
}

@Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), fingerprintMapSerializer, hashCodeSerializer);
int result = fingerprintMapSerializer.hashCode();
result = 31 * result + hashCodeSerializer.hashCode();
return result;
}
}
Expand Up @@ -19,6 +19,8 @@
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.internal.fingerprint.FileNormalizer;

import java.util.Locale;

// TODO Break this up between simple normalizers and Java classpath normalizers
// The latter should be moved to :normalization-java
public enum InputNormalizer implements FileNormalizer {
Expand All @@ -34,7 +36,7 @@ public enum InputNormalizer implements FileNormalizer {

InputNormalizer(boolean ignoreDirectories) {
this.ignoreDirectories = ignoreDirectories;
this.description = name().toLowerCase().replace('_', ' ');
this.description = name().toLowerCase(Locale.ROOT).replace('_', ' ');
}

public static FileNormalizer determineNormalizerForPathSensitivity(PathSensitivity pathSensitivity) {
Expand Down
Expand Up @@ -39,6 +39,7 @@
import org.gradle.work.NormalizeLineEndings;

import java.lang.annotation.Annotation;
import java.util.Locale;

import static org.gradle.internal.deprecation.Documentation.userManual;
import static org.gradle.internal.execution.model.annotations.ModifierAnnotationCategory.NORMALIZATION;
Expand Down Expand Up @@ -117,7 +118,7 @@ public void validatePropertyMetadata(PropertyMetadata propertyMetadata, TypeVali
.forProperty(propertyName)
.id(MISSING_NORMALIZATION_ID.getName(), MISSING_NORMALIZATION_ID.getDisplayName(), MISSING_NORMALIZATION_ID.getGroup()) // TODO (donat) missing test coverage
.contextualLabel(String.format("is annotated with @%s but missing a normalization strategy", getAnnotationType().getSimpleName()))
.documentedAt(userManual("validation_problems", MISSING_NORMALIZATION_ANNOTATION.toLowerCase()))
.documentedAt(userManual("validation_problems", MISSING_NORMALIZATION_ANNOTATION.toLowerCase(Locale.ROOT)))
.severity(Severity.ERROR)
.details("If you don't declare the normalization, outputs can't be re-used between machines or locations on the same machine, therefore caching efficiency drops significantly")
.solution("Declare the normalization strategy by annotating the property with either @PathSensitive, @Classpath or @CompileClasspath");
Expand Down
Expand Up @@ -31,6 +31,7 @@
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import static org.gradle.internal.deprecation.Documentation.userManual;

Expand Down Expand Up @@ -75,7 +76,7 @@ private static void validateUnsupportedPropertyValueType(
TypeOf.typeOf(propertyMetadata.getDeclaredType().getType()).getSimpleName()
)
)
.documentedAt(userManual("validation_problems", UNSUPPORTED_VALUE_TYPE.toLowerCase()))
.documentedAt(userManual("validation_problems", UNSUPPORTED_VALUE_TYPE.toLowerCase(Locale.ROOT)))
.severity(Severity.ERROR)
.details(String.format("%s is not supported on task properties annotated with @%s", unsupportedType.getSimpleName(), annotationType.getSimpleName()));
for (String possibleSolution : possibleSolutions) {
Expand Down
Expand Up @@ -35,6 +35,7 @@
import java.io.File;
import java.net.URL;
import java.util.List;
import java.util.Locale;

import static org.gradle.api.problems.Severity.WARNING;
import static org.gradle.internal.deprecation.Documentation.userManual;
Expand Down Expand Up @@ -77,7 +78,7 @@ private void validateNotOptionalPrimitiveType(PropertyMetadata propertyMetadata,
.forProperty(propertyMetadata.getPropertyName())
.id(TextUtil.screamingSnakeToKebabCase(CANNOT_USE_OPTIONAL_ON_PRIMITIVE_TYPES), "Property should be annotated with @Optional", GradleCoreProblemGroup.validation().property())
.contextualLabel(String.format("of type %s shouldn't be annotated with @Optional", valueType.getName()))
.documentedAt(userManual(VALIDATION_PROBLEMS, CANNOT_USE_OPTIONAL_ON_PRIMITIVE_TYPES.toLowerCase()))
.documentedAt(userManual(VALIDATION_PROBLEMS, CANNOT_USE_OPTIONAL_ON_PRIMITIVE_TYPES.toLowerCase(Locale.ROOT)))
.details("Properties of primitive type cannot be optional")
.severity(Severity.ERROR)
.solution("Remove the @Optional annotation")
Expand All @@ -99,7 +100,7 @@ private void validateNotFileType(PropertyMetadata propertyMetadata, TypeValidati
.forProperty(propertyMetadata.getPropertyName())
.id(TextUtil.screamingSnakeToKebabCase(INCORRECT_USE_OF_INPUT_ANNOTATION), "Incorrect use of @Input annotation", GradleCoreProblemGroup.validation().property())
.contextualLabel(String.format("has @Input annotation used on property of type '%s'", ModelType.of(valueType).getDisplayName()))
.documentedAt(userManual(VALIDATION_PROBLEMS, INCORRECT_USE_OF_INPUT_ANNOTATION.toLowerCase()))
.documentedAt(userManual(VALIDATION_PROBLEMS, INCORRECT_USE_OF_INPUT_ANNOTATION.toLowerCase(Locale.ROOT)))
.severity(Severity.ERROR)
.details("A property of type '" + ModelType.of(valueType).getDisplayName() + "' annotated with @Input cannot determine how to interpret the file")
.solution("Annotate with @InputFile for regular files")
Expand All @@ -117,7 +118,7 @@ private void validateNotDirectoryType(PropertyMetadata propertyMetadata, TypeVal
.forProperty(propertyMetadata.getPropertyName())
.id(TextUtil.screamingSnakeToKebabCase(INCORRECT_USE_OF_INPUT_ANNOTATION), "Incorrect use of @Input annotation", GradleCoreProblemGroup.validation().property())
.contextualLabel(String.format("has @Input annotation used on property of type '%s'", ModelType.of(valueType).getDisplayName()))
.documentedAt(userManual(VALIDATION_PROBLEMS, INCORRECT_USE_OF_INPUT_ANNOTATION.toLowerCase()))
.documentedAt(userManual(VALIDATION_PROBLEMS, INCORRECT_USE_OF_INPUT_ANNOTATION.toLowerCase(Locale.ROOT)))
.severity(Severity.ERROR)
.details("A property of type '" + ModelType.of(valueType).getDisplayName() + "' annotated with @Input cannot determine how to interpret the file")
.solution("Annotate with @InputDirectory for directories")
Expand All @@ -136,7 +137,7 @@ private static void validateNotUrlType(PropertyMetadata propertyMetadata, TypeVa
.forProperty(propertyMetadata.getPropertyName())
.id(TextUtil.screamingSnakeToKebabCase(UNSUPPORTED_VALUE_TYPE) + "-for-input", "Unsupported value type for @Input annotation", GradleCoreProblemGroup.validation().property())
.contextualLabel(String.format("has @Input annotation used on type '%s' or a property of this type", URL.class.getName()))
.documentedAt(userManual(VALIDATION_PROBLEMS, UNSUPPORTED_VALUE_TYPE.toLowerCase()))
.documentedAt(userManual(VALIDATION_PROBLEMS, UNSUPPORTED_VALUE_TYPE.toLowerCase(Locale.ROOT)))
.severity(WARNING)
.details(String.format("Type '%s' is not supported on properties annotated with @Input because Java Serialization can be inconsistent for this type", URL.class.getName()))
.solution("Use type 'java.net.URI' instead")
Expand Down
Expand Up @@ -32,6 +32,7 @@

import java.lang.reflect.ParameterizedType;
import java.util.List;
import java.util.Locale;

import static org.gradle.internal.deprecation.Documentation.userManual;
import static org.gradle.internal.execution.model.annotations.ModifierAnnotationCategory.OPTIONAL;
Expand Down Expand Up @@ -68,7 +69,7 @@ public void validatePropertyMetadata(PropertyMetadata propertyMetadata, TypeVali
.forProperty(propertyMetadata.getPropertyName())
.id(TextUtil.screamingSnakeToKebabCase(SERVICE_REFERENCE_MUST_BE_A_BUILD_SERVICE), "Property has @ServiceReference annotation", GradleCoreProblemGroup.validation().property()) // TODO (donat) missing test coverage
.contextualLabel(String.format("has @ServiceReference annotation used on property of type '%s' which is not a build service implementation", typeVariables.get(0).getName()))
.documentedAt(userManual("validation_problems", SERVICE_REFERENCE_MUST_BE_A_BUILD_SERVICE.toLowerCase()))
.documentedAt(userManual("validation_problems", SERVICE_REFERENCE_MUST_BE_A_BUILD_SERVICE.toLowerCase(Locale.ROOT)))
.severity(Severity.ERROR)
.details(String.format("A property annotated with @ServiceReference must be of a type that implements '%s'", BuildService.class.getName()))
.solution(String.format("Make '%s' implement '%s'", typeVariables.get(0).getName(), BuildService.class.getName()))
Expand Down
Expand Up @@ -32,6 +32,7 @@ public CancelExecutionStep(
this.delegate = delegate;
}

@SuppressWarnings("Finally")
@Override
public R execute(UnitOfWork work, C context) {
Thread thread = Thread.currentThread();
Expand Down
Expand Up @@ -42,6 +42,8 @@
* All changes to the outputs must be done at this point, so this step needs to be around anything
* which uses an {@link ChangingOutputsContext}.
*/
// TODO Find better names for Result types
@SuppressWarnings("SameNameButDifferent")
public class CaptureOutputsAfterExecutionStep<C extends WorkspaceContext & CachingContext> extends BuildOperationStep<C, AfterExecutionResult> {
private final UniqueId buildInvocationScopeId;
private final OutputSnapshotter outputSnapshotter;
Expand Down
Expand Up @@ -21,7 +21,6 @@
import org.gradle.internal.Try;
import org.gradle.internal.execution.ExecutionEngine.Execution;
import org.gradle.internal.execution.UnitOfWork;
import org.gradle.internal.execution.history.BeforeExecutionState;
import org.gradle.internal.execution.history.ExecutionOutputState;
import org.gradle.internal.execution.history.PreviousExecutionState;
import org.gradle.internal.execution.history.impl.DefaultExecutionOutputState;
Expand Down Expand Up @@ -50,11 +49,11 @@ public UpToDateResult execute(UnitOfWork work, C context) {
ImmutableList<String> reasons = context.getRebuildReasons();
return context.getChanges()
.filter(__ -> reasons.isEmpty())
.map(changes -> skipExecution(work, changes.getBeforeExecutionState(), context))
.map(changes -> skipExecution(work, context))
.orElseGet(() -> executeBecause(work, reasons, context));
}

private UpToDateResult skipExecution(UnitOfWork work, BeforeExecutionState beforeExecutionState, C context) {
private UpToDateResult skipExecution(UnitOfWork work, C context) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Skipping {} as it is up-to-date.", work.getDisplayName());
}
Expand Down
Expand Up @@ -56,6 +56,7 @@ public R execute(UnitOfWork work, C context) {
}
}

@SuppressWarnings("Finally")
private R executeWithTimeout(UnitOfWork work, C context, Duration timeout) {
Timeout taskTimeout = timeoutHandler.start(Thread.currentThread(), timeout, work, currentBuildOperationRef.get());
try {
Expand Down