Skip to content

Fix NPE when application password response is missing password or UUID#22952

Open
adalpari wants to merge 2 commits into
release/26.8from
fix/application-password-null-fields-crash
Open

Fix NPE when application password response is missing password or UUID#22952
adalpari wants to merge 2 commits into
release/26.8from
fix/application-password-null-fields-crash

Conversation

@adalpari

@adalpari adalpari commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes a crash when the WordPress.com / WP-API application password endpoint returns a 200 response that is missing the password or uuid field.

ApplicationPasswordCreationResponse declared its fields as non-null, but Gson populates objects via reflection and bypasses Kotlin's null-safety. When the field is absent/null in the JSON, the value flowed into the non-null ApplicationPasswordCreationPayload constructor and threw an NPE. In the minified release build the parameter null-check compiles to a bare getClass() call, which is exactly the reported crash signature.

Fix

  • Made uuid, name, and password on ApplicationPasswordCreationResponse nullable to match what Gson can actually produce.
  • Validate the fields on the success path; when either password or uuid is missing, return the existing error payload ("Password or UUID missing from response") instead of crashing. The result propagates as a normal ApplicationPasswordCreationResult.Failure — the same path used for other creation errors.
  • Applied to both JetpackApplicationPasswordsRestClient (where the crash was reported) and WPApiApplicationPasswordsRestClient, which share the response type.

Tests

Added unit tests for both clients covering: valid response, null password, null uuid, null body, and network error.

Crash report

https://a8c.sentry.io/issues/7522022287/?environment=prod&environment=release&project=5731682&query=release%3A%22com.jetpack.android%4026.8-rc-5%2B1493%22&referrer=release-issue-stream

Reported on com.jetpack.android@26.8-rc-5+1493.

🤖 Generated with Claude Code

@dangermattic

dangermattic commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator
1 Warning
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@adalpari adalpari changed the base branch from trunk to release/26.8 June 8, 2026 14:13
The Gson-deserialized ApplicationPasswordCreationResponse declared its
fields as non-null, but Gson populates objects via reflection and bypasses
Kotlin's null checks. When the API returns a 200 response missing the
`password` or `uuid` field, those nulls flowed into the non-null
ApplicationPasswordCreationPayload constructor, crashing the app (in the
minified release build the parameter null-check compiles to a bare
getClass() call, producing the reported NPE).

Make the response fields nullable and validate them, returning the existing
error payload instead of crashing. Applied to both the Jetpack and WP-API
clients, which share the response type.

Crash report: https://a8c.sentry.io/issues/7522022287/

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@adalpari adalpari force-pushed the fix/application-password-null-fields-crash branch from dda20c6 to 0da0911 Compare June 8, 2026 14:14
@wpmobilebot

wpmobilebot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in WordPress Android by scanning the QR code below to install the corresponding build.

App NameWordPress Android
Build TypeDebug
Versionpr22952-34da930
Build Number1493
Application IDorg.wordpress.android.prealpha
Commit34da930
Installation URL20glo7e6rddi0
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in Jetpack Android by scanning the QR code below to install the corresponding build.

App NameJetpack Android
Build TypeDebug
Versionpr22952-34da930
Build Number1493
Application IDcom.jetpack.android.prealpha
Commit34da930
Installation URL780eqs7u14q5o
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

Copy link
Copy Markdown
Contributor

🤖 Build Failure Analysis

This build has failures. Claude has analyzed them - check the build annotations for details.

@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.47619% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.38%. Comparing base (f70a22a) to head (34da930).

Files with missing lines Patch % Lines
...passwords/JetpackApplicationPasswordsRestClient.kt 80.00% 2 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff                @@
##           release/26.8   #22952      +/-   ##
================================================
+ Coverage         37.34%   37.38%   +0.03%     
================================================
  Files              2320     2320              
  Lines            124714   124718       +4     
  Branches          16959    16963       +4     
================================================
+ Hits              46580    46631      +51     
+ Misses            74370    74323      -47     
  Partials           3764     3764              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@adalpari adalpari marked this pull request as ready for review June 9, 2026 18:05
@adalpari adalpari requested a review from nbradbury June 9, 2026 18:05

@nbradbury nbradbury left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good! :shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants