Skip to content

Commit e8cf6f9

Browse files
fix: handle null pointer when parsing metadata attributes (#759)
* fix: handle null pointer when parsing metadata attributes Fix behavior of getRegion and getZone methods when attributes aren't defined. Align getNamespaceName return value with other methods to return null. * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 23f7fa5 commit e8cf6f9

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

google-cloud-logging/src/main/java/com/google/cloud/logging/MetadataLoader.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ private String getModuleId() {
137137
* K8S_POD_NAMESPACE_PATH} when available or read from a user defined environment variable
138138
* "NAMESPACE_NAME"
139139
*
140-
* @return Namespace name or empty string if the name could not be discovered
140+
* @return Namespace string or null if the name could not be discovered
141141
*/
142142
private String getNamespaceName() {
143-
String value = "";
143+
String value = null;
144144
try {
145145
value =
146146
new String(
@@ -151,9 +151,6 @@ private String getNamespaceName() {
151151
// if SA token is not shared the info about namespace is unavailable
152152
// allow users to define the namespace name explicitly
153153
value = getter.getEnv("NAMESPACE_NAME");
154-
if (value == null) {
155-
value = "";
156-
}
157154
}
158155
return value;
159156
}
@@ -178,7 +175,10 @@ private String getProjectId() {
178175
*/
179176
private String getRegion() {
180177
String loc = getter.getAttribute("instance/region");
181-
return loc.substring(loc.lastIndexOf('/') + 1);
178+
if (loc != null) {
179+
return loc.substring(loc.lastIndexOf('/') + 1);
180+
}
181+
return null;
182182
}
183183

184184
private String getRevisionName() {
@@ -199,6 +199,9 @@ private String getVersionId() {
199199
*/
200200
private String getZone() {
201201
String loc = getter.getAttribute("instance/zone");
202-
return loc.substring(loc.lastIndexOf('/') + 1);
202+
if (loc != null) {
203+
return loc.substring(loc.lastIndexOf('/') + 1);
204+
}
205+
return null;
203206
}
204207
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy