Directory synchronization fails - NullPointerException in the DirectoryUserRenamedEvent

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Synchronization to the external directory fails without any error message in the UI.

Environment

Confluence Server or Data Center
LDAP Directory

Diagnosis

In the application logs, we don't see any log messages reporting that the directory synchronization started.
Instead, we see a DirectoryUserRenamedEvent ending up in a NullPointerException:

atlassian-confluence.log
2021-06-10 10:38:25,428 ERROR [Caesium-1-1] [atlassian.confluence.event.ConfluenceEventDispatcher] run There was an exception thrown trying to dispatch event [com.atlassian.confluence.event.events.user.DirectoryUserRenamedEvent[source=com.atlassian.confluence.impl.user.crowd.CachedCrowdUserDao@3f96ef2]] from the invoker [SingleParameterMethodListenerInvoker{method=public void com.atlassian.confluence.user.listeners.UserDirectoryListener.onUserRenamedEvent(com.atlassian.confluence.event.events.user.DirectoryUserRenamedEvent), listener=com.atlassian.confluence.user.listeners.UserDirectoryListener@1b36eb4b} (timed)]
java.lang.RuntimeException: Listener: com.atlassian.confluence.user.listeners.UserDirectoryListener event: com.atlassian.confluence.event.events.user.DirectoryUserRenamedEvent
...
Caused by: java.lang.NullPointerException


We can see a user that exists in the cwd_user table and doesn't exist in the user_mapping table, by running the following query:


SELECT * FROM cwd_user WHERE user_name NOT IN (
	SELECT username FROM user_mapping);

Confluence is trying to rename a user that was never created in the user_mapping table. By Enabling Detailed SQL Logging we can see the SQL statements trying to rename the user:

2021-06-14 13:02:49,193 DEBUG [Caesium-1-3] [org.hibernate.SQL] logStatement select confluence0_.user_key as user_key1_71_, confluence0_.username as username2_71_, confluence0_.lower_username as lower_us3_71_ from user_mapping confluence0_ where confluence0_.lower_username=?

2021-06-14 13:02:49,194 TRACE [Caesium-1-3] [type.descriptor.sql.BasicBinder] bind binding parameter [1] as [VARCHAR] - [\User.name@company.com]

Cause

The root cause for the issue is unknown yet. We may add more details when we identify it.

What we could identify so far is that the user was previously synced with an invalid character in the username and the rename isn't working.

atlassian-confluence-sql.log
2021-06-14 13:02:49,185 DEBUG [Caesium-1-3] [org.hibernate.SQL] logStatement update cwd_user set user_name=?, lower_user_name=?, active=?, created_date=?, updated_date=?, first_name=?, lower_first_name=?, last_name=?, lower_last_name=?, display_name=?, lower_display_name=?, email_address=?, lower_email_address=?, external_id=?, directory_id=?, credential=? where id=?
2021-06-14 13:02:49,186 TRACE [Caesium-1-3] [type.descriptor.sql.BasicBinder] bind binding parameter [1] as [VARCHAR] - [user.name@company.com]
2021-06-14 13:02:49,186 TRACE [Caesium-1-3] [type.descriptor.sql.BasicBinder] bind binding parameter [2] as [VARCHAR] - [user.name@company.com]
2021-06-14 13:02:49,186 TRACE [Caesium-1-3] [type.descriptor.sql.BasicBinder] bind binding parameter [3] as [CHAR] - [true]
2021-06-14 13:02:49,186 TRACE [Caesium-1-3] [type.descriptor.sql.BasicBinder] bind binding parameter [4] as [TIMESTAMP] - [2021-04-06 08:42:17.0]
2021-06-14 13:02:49,186 TRACE [Caesium-1-3] [type.descriptor.sql.BasicBinder] bind binding parameter [5] as [TIMESTAMP] - [Mon Jun 14 13:02:49 EDT 2021]
2021-06-14 13:02:49,187 TRACE [Caesium-1-3] [type.descriptor.sql.BasicBinder] bind binding parameter [6] as [VARCHAR] - [User]
2021-06-14 13:02:49,187 TRACE [Caesium-1-3] [type.descriptor.sql.BasicBinder] bind binding parameter [7] as [VARCHAR] - [user]
2021-06-14 13:02:49,187 TRACE [Caesium-1-3] [type.descriptor.sql.BasicBinder] bind binding parameter [8] as [VARCHAR] - [Name]
2021-06-14 13:02:49,187 TRACE [Caesium-1-3] [type.descriptor.sql.BasicBinder] bind binding parameter [9] as [VARCHAR] - [name]
2021-06-14 13:02:49,187 TRACE [Caesium-1-3] [type.descriptor.sql.BasicBinder] bind binding parameter [10] as [VARCHAR] - [User Name]
2021-06-14 13:02:49,187 TRACE [Caesium-1-3] [type.descriptor.sql.BasicBinder] bind binding parameter [11] as [VARCHAR] - [user name]
2021-06-14 13:02:49,187 TRACE [Caesium-1-3] [type.descriptor.sql.BasicBinder] bind binding parameter [12] as [VARCHAR] - [\User.name@company.com]
2021-06-14 13:02:49,188 TRACE [Caesium-1-3] [type.descriptor.sql.BasicBinder] bind binding parameter [13] as [VARCHAR] - [\user.name@company.com]
2021-06-14 13:02:49,188 TRACE [Caesium-1-3] [type.descriptor.sql.BasicBinder] bind binding parameter [14] as [VARCHAR] - [73c84e01-916a11eb-8b4dd22e-ed9db717]
2021-06-14 13:02:49,188 TRACE [Caesium-1-3] [type.descriptor.sql.BasicBinder] bind binding parameter [15] as [BIGINT] - [<Directory_ID>]
2021-06-14 13:02:49,188 TRACE [Caesium-1-3] [type.descriptor.sql.BasicBinder] bind binding parameter [16] as [VARCHAR] - [X]
2021-06-14 13:02:49,188 TRACE [Caesium-1-3] [type.descriptor.sql.BasicBinder] bind binding parameter [17] as [BIGINT] - [<User_ID>]


Solution

Always backup Confluence before directly changing the Database.

We also recommend testing the solution on a Staging Environment before applying it to production

  1. Stop Confluence
  2. (warning) Perform a backup of Confluence Database
  3. Run the following SQL query to manually rename the user in the cwd_user table:

    UPDATE cwd_user
    SET user_name = '<Username>',
    lower_user_name = '<Lower_Username>',
    WHERE id = <User_ID>;

    (info) Replace the fields according to the information found in the SQL Logging

  4. Start Confluence


Last modified on Dec 8, 2022

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.