From 3b6f805fe8ac1374a19096224b444d2f6d8a43e4 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 4 Aug 2023 09:05:29 -0700 Subject: [PATCH] Store marker data in a TreeMap instead of a HashMap. The iteration order of HashMap is non-deterministic and we did not sort the keys before iterating over them, which means that the contents of the marker file were also non-deterministic. This was broken in unknown commit which inadvertently replaced a TreeMap with a HashMap here. RELNOTES: None. PiperOrigin-RevId: 553823566 Change-Id: Id83ac059d28c24b2149c82e85c25307865516116 --- .../lib/rules/repository/RepositoryDelegatorFunction.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 aa92bfd1a6db34..a8e2a081455c60 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 @@ -507,14 +507,15 @@ static String unescape(String str) { private static class DigestWriter { private final Path markerPath; private final Rule rule; - private final Map markerData; + // not just Map<> to signal that iteration order must be deterministic + private final TreeMap markerData; private final String ruleKey; DigestWriter(BlazeDirectories directories, RepositoryName repositoryName, Rule rule) { ruleKey = computeRuleKey(rule); markerPath = getMarkerPath(directories, repositoryName.getName()); this.rule = rule; - markerData = Maps.newHashMap(); + markerData = Maps.newTreeMap(); } byte[] writeMarkerFile() throws RepositoryFunctionException {