8000 fix: prevent NPE in AccountLoader when theme is unavailable by lukman48 · Pull Request #48813 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

fix: prevent NPE in AccountLoader when theme is unavailable - #48813

Closed
lukman48 wants to merge 1 commit into
keycloak:mainfrom
lukman48:fix/account-loader-npe-48806
Closed

lukman48 wants to merge 1 commit into
keycloak:mainfrom
lukman48:fix/account-loader-npe-48806

Conversation

@lukman48
@lukman48 lukman48 commented May 7, 2026
Copy link
8000
Copy Markdown

Issue

Fixes #48806 - NPE when accessing Account UI and the ACCOUNT feature is disabled

Problem

When the ACCOUNT_V3 feature is disabled, accessing the account console endpoint throws a NullPointerException in AccountLoader.getAccountResourceProvider().

Root Cause

The theme parameter passed to getAccountResourceProvider() can be null when the account theme is unavailable (e.g., when account-v3 feature is disabled), but the method unconditionally calls theme.getProperties() without a null check.

Stack Trace

java.lang.NullPointerException
  at org.keycloak.services.resources.account.AccountLoader.getAccountResourceProvider(AccountLoader.java:172)
  at org.keycloak.services.resources.account.AccountLoader.getAccountService(AccountLoader.java:87)
  ...

Solution

Add a null check before accessing theme properties:

// Before:
if (theme.getProperties().containsKey(Theme.ACCOUNT_RESOURCE_PROVIDER_KEY)) {

// After:
if (theme != null && theme.getProperties().containsKey(Theme.ACCOUNT_RESOURCE_PROVIDER_KEY)) {

This allows the method to gracefully handle the case when theme is null by returning the default provider.

Testing

Manual Test Steps

  1. Start Keycloak with --features-disabled=account-v3
  2. Navigate to the Admin Console
  3. Click the user dropdown in the top-right navbar
  4. Select "Manage account"
  5. ✅ Should no longer throw NPE / 500 error
  6. Behavior should be consistent with other unavailable features

Expected Behavior

  • No NPE thrown
  • Request is handled gracefully
  • Appropriate error or fallback behavior occurs

Impact

  • Minimal Change: Single line addition (null check)
  • No Behavioral Change: Falls back to default provider when theme is null
  • Backward Compatible: 100% compatible with existing code
  • Fixes Regression: Resolves NPE that occurs when account feature is disabled

Related Labels: kind/bug, area/account/api, priority/normal, help wanted

@lukman48
lukman48 requested a review from a team as a code owner May 7, 2026 22:03
…#48806)

When the ACCOUNT_V3 feature is disabled, accessing the account console endpoint
throws a NullPointerException in AccountLoader.getAccountResourceProvider() because
the theme parameter can be null, but the code unconditionally calls theme.getProperties().

Add null check before accessing theme properties to handle the case gracefully
when the account theme is unavailable (e.g., when account feature is disabled).

Fixes keycloak#48806

Signed-off-by: lukman48 <lukman_uki@yahoo.co.id>
@lukman48
lukman48 force-pushed the fix/account-loader-npe-48806 branch from f6bde83 to f57c6ad Compare May 8, 2026 02:29
@mabartos
Copy link
Copy Markdown
Member

@lukman48 Thanks for the PR! But we should rather go with this approach as it covers more areas:

@mabartos mabartos closed this May 11, 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.

NPE when accessing Account UI and the ACCOUNT feature is disabled

2 participants

0