Skip to content

Conversation

@ArafatKhan2198
Copy link
Contributor

What changes were proposed in this pull request?

  • This issue arose from direct calls to methods like .asInt() and .asText() on potentially null JsonNode objects returned by .get(String) when the expected keys were missing in the JSON response.
Cannot invoke "com.fasterxml.jackson.databind.JsonNode.asInt()" because the return value of
"com.fasterxml.jackson.databind.JsonNode.get(String)" is null
  • To resolve this, we employed the .path(String) method followed by .asInt(defaultValue) or .asText(defaultValue) to safely access and convert JSON fields. The .path(String) method ensures a null-safe way to access JSON fields, returning a "missing node" instead of null for absent keys, thereby preventing NPEs. Furthermore, by specifying default values for .asInt(defaultValue) and .asText(defaultValue), we ensured that our code could handle missing or unexpected data gracefully, defaulting to a pre-defined value instead of crashing or behaving unpredictably.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-10581

How was this patch tested?

@ArafatKhan2198
Copy link
Contributor Author

@adoroszlai @devabhishekpal @devmadhuu Could you please take a look.

Copy link
Contributor

@adoroszlai adoroszlai left a comment

Choose a reason for hiding this comment

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

Thanks @ArafatKhan2198 for the patch.

@adoroszlai adoroszlai merged commit e39166f into apache:master Mar 24, 2024
smitajoshi12 pushed a commit to smitajoshi12/ozone that referenced this pull request Mar 27, 2024
jojochuang pushed a commit to jojochuang/ozone that referenced this pull request May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants