Skip to content

Commit 5c4becc

Browse files
zhengwei143copybara-github
authored andcommitted
Fix NPE in ResourceManager when collecting local resource estimation in the profiler.
Fixes #21133. RELNOTES: None. PiperOrigin-RevId: 603631744 Change-Id: Ied224fd14e2be1465098135e0cab87584bbedb28
1 parent f8c5b4c commit 5c4becc

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/main/java/com/google/devtools/build/lib/actions/ResourceManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@ public static ResourceManager instance() {
165165
/** Returns prediction of RAM in Mb used by registered actions. */
166166
@Override
167167
public double getUsedMemoryInMb() {
168-
return usedResources.get(ResourceSet.MEMORY);
168+
return usedResources.getOrDefault(ResourceSet.MEMORY, 0d);
169169
}
170170

171171
/** Returns prediction of CPUs used by registered actions. */
172172
@Override
173173
public double getUsedCPU() {
174-
return usedResources.get(ResourceSet.CPU);
174+
return usedResources.getOrDefault(ResourceSet.CPU, 0d);
175175
}
176176

177177
// Allocated resources are allowed to go "negative", but at least
@@ -207,7 +207,7 @@ public double getUsedCPU() {
207207

208208
// Used amount of resources. Corresponds to the resource
209209
// definition in the ResourceSet class.
210-
private Map<String, Double> usedResources;
210+
private Map<String, Double> usedResources = new HashMap<>();
211211

212212
// Used local test count. Corresponds to the local test count definition in the ResourceSet class.
213213
private int usedLocalTestCount;

0 commit comments

Comments
 (0)