Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle null pointer when parsing metadata attributes #759

Merged
merged 2 commits into from Nov 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -137,10 +137,10 @@ private String getModuleId() {
* K8S_POD_NAMESPACE_PATH} when available or read from a user defined environment variable
* "NAMESPACE_NAME"
*
* @return Namespace name or empty string if the name could not be discovered
* @return Namespace string or null if the name could not be discovered
*/
private String getNamespaceName() {
String value = "";
String value = null;
try {
value =
new String(
Expand All @@ -151,9 +151,6 @@ private String getNamespaceName() {
// if SA token is not shared the info about namespace is unavailable
// allow users to define the namespace name explicitly
value = getter.getEnv("NAMESPACE_NAME");
if (value == null) {
value = "";
}
}
return value;
}
Expand All @@ -178,7 +175,10 @@ private String getProjectId() {
*/
private String getRegion() {
String loc = getter.getAttribute("instance/region");
return loc.substring(loc.lastIndexOf('/') + 1);
if (loc != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: return loc != null ? loc.substring(loc.lastIndexOf('/') + 1) : null;

return loc.substring(loc.lastIndexOf('/') + 1);
}
return null;
}

private String getRevisionName() {
Expand All @@ -199,6 +199,9 @@ private String getVersionId() {
*/
private String getZone() {
String loc = getter.getAttribute("instance/zone");
return loc.substring(loc.lastIndexOf('/') + 1);
if (loc != null) {
return loc.substring(loc.lastIndexOf('/') + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Same as above - simplifies reading

}
return null;
}
}