Fix NPE when creating app password for site with no username - #22984
Conversation
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>
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>
|
|
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
@adalpari Claude flagged this:
|
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>
I've added that change now. Thanks! |
* 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>
* 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>


Description
Fixes a
NullPointerExceptionthrown while creating an Application Password for a self-hosted site that has no stored username.In
ApplicationPasswordsManager.getOrFetchUsername, a non-WPCOM site passedsite.usernamestraight intoUsernameFetchPayload's non-nullStringconstructor. SinceSiteModel.usernameis a Java (nullable) field, a null value triggered the compiler-generated overload-disambiguationgetClass()check, crashing with:The fix guards for a null/empty username and returns a
NOT_AUTHENTICATEDerror payload instead of crashing. The existing caller already converts an error payload into anApplicationPasswordCreationResult.Failure, consistent with the equivalent guard increateApplicationPassword.Testing instructions
I don't think there's a manual way to test this.