Skip to content

Conversation

@Nepomuk5665
Copy link

Summary

This PR fixes a potential NullPointerException in the Page.buildNextGenPage method that can occur when parsing JSON responses from next-gen API endpoints.

Bug Description

In buildNextGenPage, the code retrieves JsonNode values from the meta object and calls .isNull() on them without first checking if they are null:

JsonNode nextPageNode = meta.get("next_page_url");
if (!nextPageNode.isNull()) {  // NPE if nextPageNode is null
    builder.nextPageUrl(nextPageNode.asText());
}

The meta.get("key") method returns Java null when the key doesn't exist in the JSON. Calling .isNull() on a null reference throws NullPointerException.

Fix

Added null checks before calling .isNull(), following the same pattern already used in the buildPage method:

JsonNode nextPageNode = meta.get("next_page_url");
if (nextPageNode != null && !nextPageNode.isNull()) {
    builder.nextPageUrl(nextPageNode.asText());
}

Affected Fields

  • next_page_url
  • previous_page_url
  • first_page_url
  • page_size

All four fields now have proper null checks.

Testing

The fix follows the existing pattern in buildPage (lines 153-173) which correctly handles this case.

Add null checks before calling isNull() on JsonNode objects retrieved
from meta object. The meta.get() method returns null (Java null) when
the key doesn't exist, and calling isNull() on a null reference throws
NullPointerException.

This fix aligns buildNextGenPage with the pattern already used in
buildPage, which correctly checks 'node != null && !node.isNull()'
before accessing the node's value.
@Nepomuk5665 Nepomuk5665 changed the title Fix potential NullPointerException in Page.buildNextGenPage method fix: prevent NullPointerException in Page.buildNextGenPage Jan 24, 2026
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.

1 participant