We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b04f046 commit cb44cb7Copy full SHA for cb44cb7
1 file changed
google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java
@@ -364,9 +364,14 @@ public String getProjectId() {
364
365
String projectIdFromMetadata = getProjectIdFromMetadata();
366
synchronized (this) {
367
- this.projectId = projectIdFromMetadata;
+ // Check first if another thread set the Project ID. No need to overwrite
368
+ // if a Projects ID already exists. Tries to prevent a case where the last call
369
+ // for `getProjectIdFromMetadata()` returns null and overwrites valid data.
370
+ if (this.projectId == null) {
371
+ this.projectId = projectIdFromMetadata;
372
+ }
373
}
- return projectIdFromMetadata;
374
+ return this.projectId;
375
376
377
private String getProjectIdFromMetadata() {
0 commit comments