Skip to content

Fix NPE when creating app password for site with no username - #22984

Merged
adalpari merged 4 commits into
release/26.8from
fix/app-password-null-username
Jun 15, 2026
Merged

Fix NPE when creating app password for site with no username#22984
adalpari merged 4 commits into
release/26.8from
fix/app-password-null-username

Conversation

@adalpari

@adalpari adalpari commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes a NullPointerException thrown while creating an Application Password for a self-hosted site that has no stored username.

In ApplicationPasswordsManager.getOrFetchUsername, a non-WPCOM site passed site.username straight into UsernameFetchPayload's non-null String constructor. Since SiteModel.username is a Java (nullable) field, a null value triggered the compiler-generated overload-disambiguation getClass() check, crashing with:

java.lang.NullPointerException: Attempt to invoke virtual method
'java.lang.Class java.lang.Object.getClass()' on a null object reference
    at ...ApplicationPasswordsManager.getOrFetchUsername(ApplicationPasswordsManager.kt:77)

The fix guards for a null/empty username and returns a NOT_AUTHENTICATED error payload instead of crashing. The existing caller already converts an error payload into an ApplicationPasswordCreationResult.Failure, consistent with the equivalent guard in createApplicationPassword.

Testing instructions

I don't think there's a manual way to test this.

getOrFetchUsername passed a nullable SiteModel.username into
UsernameFetchPayload's non-null String constructor, crashing self-hosted
sites without a stored username. Guard for null/empty and return a
NOT_AUTHENTICATED error payload instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dangermattic

dangermattic commented Jun 15, 2026

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

Generated by 🚫 Danger

Verifies a non-WPCOM site with no username returns a NOT_AUTHENTICATED
Failure instead of crashing. Confirmed to reproduce the original NPE
when run against the unfixed code.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@adalpari
adalpari marked this pull request as ready for review June 15, 2026 10:45
@wpmobilebot

wpmobilebot commented Jun 15, 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
Versionpr22984-f420d15
Build Number1495
Application IDorg.wordpress.android.prealpha
Commitf420d15
Installation URL6s9r5oh0nuk7g
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Jun 15, 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
Versionpr22984-f420d15
Build Number1495
Application IDcom.jetpack.android.prealpha
Commitf420d15
Installation URL71hndkilf2jbg
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 37.40%. Comparing base (b992ed0) to head (f420d15).

Additional details and impacted files
@@               Coverage Diff                @@
##           release/26.8   #22984      +/-   ##
================================================
+ Coverage         37.38%   37.40%   +0.01%     
================================================
  Files              2320     2320              
  Lines            124718   124725       +7     
  Branches          16963    16964       +1     
================================================
+ Hits              46631    46652      +21     
+ Misses            74323    74311      -12     
+ Partials           3764     3762       -2     

☔ 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 requested a review from nbradbury June 15, 2026 11:04
@adalpari
adalpari enabled auto-merge (squash) June 15, 2026 11:04
@nbradbury

Copy link
Copy Markdown
Contributor

@adalpari Claude flagged this:

Adjacent pre-existing bug (out of scope, worth flagging). The PR description says the new guard is “consistent with the equivalent guard in createApplicationPassword” — but that equivalent guard at lines 98-113 is actually missing a return:

adalpari and others added 2 commits June 15, 2026 14:15
The guard in createApplicationPassword constructed a Failure result but
never returned it, so execution fell through to the network call. Add
the missing return so the guard short-circuits as intended.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Verifies that a non-jetpack site with a username but no password returns
a Failure (NOT_AUTHENTICATED) without hitting the network, locking in the
short-circuit guard in createApplicationPassword.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@adalpari

Copy link
Copy Markdown
Contributor Author

@adalpari Claude flagged this:

Adjacent pre-existing bug (out of scope, worth flagging). The PR description says the new guard is “consistent with the equivalent guard in createApplicationPassword” — but that equivalent guard at lines 98-113 is actually missing a return:

I've added that change now. Thanks!

@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:

@adalpari
adalpari merged commit 5d32208 into release/26.8 Jun 15, 2026
23 checks passed
@adalpari
adalpari deleted the fix/app-password-null-username branch June 15, 2026 13:18
crazytonyli pushed a commit that referenced this pull request Jun 16, 2026
* Fix NPE when creating app password for site with no username

getOrFetchUsername passed a nullable SiteModel.username into
UsernameFetchPayload's non-null String constructor, crashing self-hosted
sites without a stored username. Guard for null/empty and return a
NOT_AUTHENTICATED error payload instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Add test for null username when creating app password

Verifies a non-WPCOM site with no username returns a NOT_AUTHENTICATED
Failure instead of crashing. Confirmed to reproduce the original NPE
when run against the unfixed code.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
crazytonyli pushed a commit that referenced this pull request Jun 16, 2026
* Fix NPE when creating app password for site with no username (#22984)

* Fix NPE when creating app password for site with no username

getOrFetchUsername passed a nullable SiteModel.username into
UsernameFetchPayload's non-null String constructor, crashing self-hosted
sites without a stored username. Guard for null/empty and return a
NOT_AUTHENTICATED error payload instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Add test for null username when creating app password

Verifies a non-WPCOM site with no username returns a NOT_AUTHENTICATED
Failure instead of crashing. Confirmed to reproduce the original NPE
when run against the unfixed code.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Update translations

* Bump version number

---------

Co-authored-by: Adalberto Plaza <adalpari@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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