Skip to content

NullPointerException after after 26.3.2 migration #41640

Open

Description

@nowheresly

Before reporting an issue

  • I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.

Area

core

Describe the bug

We get exceptions in the logs

Version

26.3.2

Regression

  • The issue is a regression

Expected behavior

no exception in the logs

Actual behavior

We got this exception:

 2025-08-04 11:46:38,469 logLevel=ERROR [org.keycloak.services.error.KeycloakErrorHandler] (executor-thread-15) Uncaught server error: java.lang.NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because the return value of "org.keycloak.representations.idm.CredentialRepresentation.getHashIterations()" is null
 	at org.keycloak.models.utils.RepresentationToModel.convertDeprecatedCredentialsFormat(RepresentationToModel.java:245)
	at org.keycloak.models.utils.RepresentationToModel.createCredentials(RepresentationToModel.java:778)
 	at org.keycloak.services.resources.admin.UsersResource.createUser(UsersResource.java:173)
 	at org.keycloak.services.resources.admin.UsersResource$quarkusrestinvoker$createUser_dbaf1f3ce12d75e1e6e52c8055b800147ead4329.invoke(Unknown Source)
 	at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
 	at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:141)
 	at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:147)
 	at io.quarkus.vertx.core.runtime.VertxCoreRecorder$15.runWith(VertxCoreRecorder.java:638)
 	at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2675)
 	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2654)
 	at org.jboss.threads.EnhancedQueueExecutor.runThreadBody(EnhancedQueueExecutor.java:1627)
 	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1594)
 	at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:11)
 	at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:11)
 	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
 	at java.base/java.lang.Thread.run(Thread.java:1583)

How to Reproduce?

No sure about it

Anything else?

No response

Activity

  1. sguilhen commented on Aug 7, 2025

    @sguilhen
    Contributor

    This was logged during a user creation. We would need more info one how the user is being created, specially the contents of the UserRepresentation (as JSON would be fine as well).

  2. nowheresly commented on Aug 7, 2025

    @nowheresly
    ContributorAuthor

    As far as I know, most of our users are created using a social identity provider. So there's no credentials stored in keycloak.

  3. rmartinc commented on Aug 8, 2025

    @rmartinc
    Contributor

    @nowheresly The stack-trace of the exception shows the user is being created through the admin API (sending some json via POST to endpoint /admin/realms/{realm}/users). We need the json that is sent to that endpoint. It seems that the json representation of the user contains some data for the password and that data is throwing this exception.

  4. 16 remaining items

  5. added a commit that references this issue on Aug 15, 2025
    95aca14
  6. added theissue type on Oct 2, 2025
  7. rahul-chakradhari commented on Feb 14, 2026

    @rahul-chakradhari

    Hi @nowheresly,

    I am an Outreachy applicant and a Java developer. I noticed the NullPointerException reported after the 26.3.2 migration. I have experience in debugging Java backend issues and would like to fix this.

    Could you please assign this to me? I am ready to investigate the stack trace and submit a PR with the necessary null-safety checks. Thanks!

  8. LouisLau-art commented on Mar 3, 2026

    @LouisLau-art

    I opened a fix PR for this issue: #46767

    It adds a null-safety check for incomplete deprecated password credentials in RepresentationToModel and returns a controlled ModelException instead of a server-side NPE.

  9. added a commit that references this issue on Jun 3, 2026
    8678b63
  10. nandinis4 commented on Jul 18, 2026

    @nandinis4

    Hi, I'd like to work on this.

    I traced the NPE to convertDeprecatedCredentialsFormat() in RepresentationToModel.java — CredentialRepresentation.getHashIterations() returns a nullable Integer, which auto-unboxes to int when passed to the PasswordCredentialData constructor, throwing NPE when the field is absent in the import payload.

    I also noticed the same pattern in the OTP path — getDigits(), getCounter(), and getPeriod() are all nullable Integer passed to OTPCredentialData's primitive int parameters. I'll fix both in one PR.

    Proposed fix: null-safe extraction with sensible defaults — -1 for hashIterations (consistent with how PasswordCredentialProvider uses it as a "use provider default" sentinel), and standard TOTP/HOTP defaults for OTP fields (6 digits, 0 counter, 30s period).

    Will open a PR shortly.

  11. moved this from Backlog to In progress in Keycloak Roadmapon Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Fields

    No fields configured for bug.

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions