Skip to content

Commit

Permalink
Fix errorprone checks
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Jan 21, 2025
1 parent 78f27e9 commit 32ae6f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ public abstract static class Parser {
* Parses a recorded input from its string representation.
*
* @param s the string representation
* @return The parsed recorded input object, or {@link #PARSE_FAILURE} if the string
* representation is invalid
* @return The parsed recorded input object, or {@link
* NeverUpToDateRepoRecordedInput#PARSE_FAILURE} if the string representation is invalid
*/
public static RepoRecordedInput parse(String s) {
List<String> parts = Splitter.on(':').limit(2).splitToList(s);
if (parts.size() < 2) {
return PARSE_FAILURE;
return NeverUpToDateRepoRecordedInput.PARSE_FAILURE;
}
for (Parser parser :
new Parser[] {
Expand All @@ -112,7 +112,7 @@ public static RepoRecordedInput parse(String s) {
return parser.parse(parts.get(1));
}
}
return PARSE_FAILURE;
return NeverUpToDateRepoRecordedInput.PARSE_FAILURE;
}

/**
Expand Down Expand Up @@ -185,10 +185,6 @@ public abstract Optional<String> isOutdated(

private static final Optional<String> UNDECIDED = Optional.of("values missing");

/** A sentinel "input" that's always out-of-date to signify parse failure. */
public static final RepoRecordedInput PARSE_FAILURE =
new NeverUpToDateRepoRecordedInput("malformed marker file entry encountered");

/**
* Represents a filesystem path stored in a way that is repo-cache-friendly. That is, if the path
* happens to point inside the current Bazel workspace (in either the main repo or an external
Expand Down Expand Up @@ -285,7 +281,7 @@ public RepoRecordedInput parse(String s) {
return new File(RepoCacheFriendlyPath.parse(s));
} catch (LabelSyntaxException e) {
// malformed inputs cause refetch
return PARSE_FAILURE;
return NeverUpToDateRepoRecordedInput.PARSE_FAILURE;
}
}
};
Expand Down Expand Up @@ -384,7 +380,7 @@ public RepoRecordedInput parse(String s) {
return new Dirents(RepoCacheFriendlyPath.parse(s));
} catch (LabelSyntaxException e) {
// malformed inputs cause refetch
return PARSE_FAILURE;
return NeverUpToDateRepoRecordedInput.PARSE_FAILURE;
}
}
};
Expand Down Expand Up @@ -475,7 +471,7 @@ public RepoRecordedInput parse(String s) {
return new DirTree(RepoCacheFriendlyPath.parse(s));
} catch (LabelSyntaxException e) {
// malformed inputs cause refetch
return PARSE_FAILURE;
return NeverUpToDateRepoRecordedInput.PARSE_FAILURE;
}
}
};
Expand Down Expand Up @@ -628,7 +624,7 @@ public RepoRecordedInput parse(String s) {
return new RecordedRepoMapping(RepositoryName.create(parts.get(0)), parts.get(1));
} catch (LabelSyntaxException | IndexOutOfBoundsException e) {
// malformed inputs cause refetch
return PARSE_FAILURE;
return NeverUpToDateRepoRecordedInput.PARSE_FAILURE;
}
}
};
Expand Down Expand Up @@ -710,6 +706,10 @@ public Optional<String> isOutdated(

/** A sentinel "input" that's always out-of-date for a given reason. */
public static final class NeverUpToDateRepoRecordedInput extends RepoRecordedInput {
/** A sentinel "input" that's always out-of-date to signify parse failure. */
public static final RepoRecordedInput PARSE_FAILURE =
new NeverUpToDateRepoRecordedInput("malformed marker file entry encountered");

private final String reason;

public NeverUpToDateRepoRecordedInput(String reason) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.google.devtools.build.lib.repository.ExternalRuleNotFoundException;
import com.google.devtools.build.lib.repository.RepositoryFailedEvent;
import com.google.devtools.build.lib.repository.RepositoryFetchProgress;
import com.google.devtools.build.lib.rules.repository.RepoRecordedInput.NeverUpToDateRepoRecordedInput;
import com.google.devtools.build.lib.rules.repository.RepositoryDirectoryValue.NoRepositoryDirectoryValue;
import com.google.devtools.build.lib.rules.repository.RepositoryFunction.AlreadyReportedRepositoryAccessException;
import com.google.devtools.build.lib.rules.repository.RepositoryFunction.RepositoryFunctionException;
Expand Down Expand Up @@ -623,7 +624,7 @@ static String unescape(String str) {
private static class DigestWriter {
// Input value map to force repo invalidation upon an invalid marker file.
private static final ImmutableMap<RepoRecordedInput, String> PARSE_FAILURE =
ImmutableMap.of(RepoRecordedInput.PARSE_FAILURE, "");
ImmutableMap.of(NeverUpToDateRepoRecordedInput.PARSE_FAILURE, "");

private final BlazeDirectories directories;
private final Path markerPath;
Expand Down Expand Up @@ -658,7 +659,8 @@ byte[] writeMarkerFile(Map<? extends RepoRecordedInput, String> recordedInputVal
return new Fingerprint().addString(content).digestAndReset();
}

sealed interface RepoDirectoryState {
private sealed interface RepoDirectoryState {
@SuppressWarnings("ArrayRecordComponent")
record UpToDate(byte[] markerDigest) implements RepoDirectoryState {}

record OutOfDate(String reason) implements RepoDirectoryState {}
Expand Down Expand Up @@ -722,7 +724,7 @@ private static Map<RepoRecordedInput, String> readMarkerFile(
// Break early, need to reload anyway. This also detects marker file version changes
// so that unknown formats are not parsed.
return ImmutableMap.of(
new RepoRecordedInput.NeverUpToDateRepoRecordedInput(
new NeverUpToDateRepoRecordedInput(
"Bazel version, flags, repo rule definition or attributes changed"),
"");
}
Expand All @@ -732,7 +734,7 @@ private static Map<RepoRecordedInput, String> readMarkerFile(
int sChar = line.indexOf(' ');
if (sChar > 0) {
RepoRecordedInput input = RepoRecordedInput.parse(unescape(line.substring(0, sChar)));
if (!input.equals(RepoRecordedInput.PARSE_FAILURE)) {
if (!input.equals(NeverUpToDateRepoRecordedInput.PARSE_FAILURE)) {
recordedInputValues.put(input, unescape(line.substring(sChar + 1)));
continue;
}
Expand Down

0 comments on commit 32ae6f8

Please sign in to comment.