Bump the messages' ids from 0 to 1.
protobuf inteprets the value 0 as "default value" for uint64, thus treating the field as
"unset". This is apparent in the textproto output: the first Artifact message
would have an empty "id" field. This wasn't a problem in analysis.proto since
we use strings as ids.
RELNOTES: None
PiperOrigin-RevId: 281929774
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/actiongraph/v2/BaseCache.java b/src/main/java/com/google/devtools/build/lib/skyframe/actiongraph/v2/BaseCache.java
index ef22f9d..f25cef1 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/actiongraph/v2/BaseCache.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/actiongraph/v2/BaseCache.java
@@ -29,7 +29,9 @@
}
private long generateNextId() {
- return cache.size();
+ // protobuf interprets the value 0 as "default value" for uint64, thus treating the field as
+ // "unset". We should start from 1 instead.
+ return cache.size() + 1L;
}
protected K transformToKey(K data) {
@@ -37,6 +39,10 @@
return data;
}
+ /**
+ * Store the data in the internal cache, if it's not yet present. Return the generated id. Ids are
+ * positive and unique.
+ */
Long dataToId(K data) {
K key = transformToKey(data);
Long id = cache.get(key);