From cfa0a284283ca6b3cbaecdaf5966cdd5e9a97e3c Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Tue, 21 Jan 2025 18:03:39 +0100 Subject: [PATCH] Fix errorprone checks --- .../rules/repository/RepoRecordedInput.java | 24 +++++++++---------- .../RepositoryDelegatorFunction.java | 8 ++++--- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/RepoRecordedInput.java b/src/main/java/com/google/devtools/build/lib/rules/repository/RepoRecordedInput.java index 84608ca3d91c23..eb1c83ce4cb0bb 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/repository/RepoRecordedInput.java +++ b/src/main/java/com/google/devtools/build/lib/rules/repository/RepoRecordedInput.java @@ -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 parts = Splitter.on(':').limit(2).splitToList(s); if (parts.size() < 2) { - return PARSE_FAILURE; + return NeverUpToDateRepoRecordedInput.PARSE_FAILURE; } for (Parser parser : new Parser[] { @@ -112,7 +112,7 @@ public static RepoRecordedInput parse(String s) { return parser.parse(parts.get(1)); } } - return PARSE_FAILURE; + return NeverUpToDateRepoRecordedInput.PARSE_FAILURE; } /** @@ -185,10 +185,6 @@ public abstract Optional isOutdated( private static final Optional 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 @@ -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; } } }; @@ -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; } } }; @@ -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; } } }; @@ -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; } } }; @@ -710,6 +706,10 @@ public Optional 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) { diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java index a62793b8559204..f8bd042a5a5568 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java @@ -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; @@ -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 PARSE_FAILURE = - ImmutableMap.of(RepoRecordedInput.PARSE_FAILURE, ""); + ImmutableMap.of(NeverUpToDateRepoRecordedInput.PARSE_FAILURE, ""); private final BlazeDirectories directories; private final Path markerPath; @@ -659,6 +660,7 @@ byte[] writeMarkerFile(Map recordedInputVal } sealed interface RepoDirectoryState { + @SuppressWarnings("ArrayRecordComponent") record UpToDate(byte[] markerDigest) implements RepoDirectoryState {} record OutOfDate(String reason) implements RepoDirectoryState {} @@ -722,7 +724,7 @@ private static Map 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"), ""); } @@ -732,7 +734,7 @@ private static Map 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; }