{"record":{"id":"4468abf5dc291895","repo":"SonarSource/sonarqube","slug":"cannot-create-unique-login-for-user-name","errorCode":null,"errorMessage":"Cannot create unique login for user name ","messagePattern":"Cannot create unique login for user name ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/sonar-webserver-auth/src/main/java/org/sonar/server/user/UserUpdater.java","lineNumber":195,"sourceCode":"      userDto.setScmAccounts(scmAccounts);\n    }\n\n    setExternalIdentity(dbSession, userDto, ExternalIdentityLocal.fromExternalIdentity(newUser.externalIdentity()));\n\n    checkRequest(messages.isEmpty(), messages);\n    return userDto;\n  }\n\n  private String generateUniqueLogin(DbSession dbSession, String userName) {\n    String slugName = slugify(userName);\n    for (int i = 0; i < 10; i++) {\n      String login = slugName + random.nextInt(100_000);\n      UserDto existingUser = dbClient.userDao().selectByLogin(dbSession, login);\n      if (existingUser == null) {\n        return login;\n      }\n    }\n    throw new IllegalStateException(\"Cannot create unique login for user name \" + userName);\n  }\n\n  private boolean updateDto(DbSession dbSession, UpdateUser update, UserDto dto) {\n    checkRequestedLocalStateIsConsistent(update, dto);\n    List<String> messages = newArrayList();\n    boolean changed = updateLogin(dbSession, update, dto, messages);\n    changed |= updateName(update, dto, messages);\n    changed |= updateEmail(update, dto, messages);\n    changed |= updateExternalIdentity(dbSession, update, dto);\n    changed |= updatePassword(dbSession, update, dto, messages);\n    changed |= updateScmAccounts(dbSession, update, dto, messages);\n    checkRequest(messages.isEmpty(), messages);\n    return changed;\n  }\n\n  private static void checkRequestedLocalStateIsConsistent(UpdateUser update, UserDto dto) {\n    if (!update.isLocalChanged() || update.local() == null) {\n      return;","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/UserUpdater.java#L177-L213","documentation":"UserUpdater.generateUniqueLogin() derives a login from the user's display name by slugging it and appending a random number, retrying until the login is not already taken in the DB. If no unique login can be produced within the retry budget, it throws IllegalStateException('Cannot create unique login for user name ...').","triggerScenarios":"Calling user creation (createDto via ws api/users/create, provisioning plugin, or SCIM) when the derived login space is saturated — i.e. thousands of existing users collide with slugName + 0..99999 suffixes.","commonSituations":"Bulk user provisioning (LDAP/SCIM sync) with many users sharing the same common name; extremely narrow retry bound exhausted on a dense user table.","solutions":["Check the users table for login collisions with the slugified name and clean up duplicate/inactive accounts","Create the user explicitly with a unique 'login' parameter instead of relying on auto-generation from the name","Retry the operation — the random suffix makes the collision transient","If provisioning thousands of same-named users, change strategy to derive logins from email or a counter rather than the name"],"exampleFix":"// before\ncurl -X POST 'http://sonar/api/users/create?name=John%20Doe'   # login auto-generated\n// after\ncurl -X POST 'http://sonar/api/users/create?login=john.doe.42&name=John%20Doe'","handlingStrategy":"try-catch","validationCode":"// pre-check login availability before auto-generation paths\nUserDto existing = dbClient.userDao().selectByLogin(dbSession, desiredLogin);\nif (existing != null) { /* choose a different explicit login */ }","typeGuard":"null","tryCatchPattern":"try {\n  userUpdater.createAndCommit(dbSession, request, context);\n} catch (IllegalStateException e) {\n  if (e.getMessage().startsWith(\"Cannot create unique login\")) {\n    // retry with explicit unique login\n  } else throw e;\n}","preventionTips":["Always pass an explicit unique login when creating users via API in bulk","Keep user logins derived from email/employee ID rather than display name","Monitor for duplicate name slugs in provisioning sync","Retry on this transient error; the random suffix changes each attempt"],"tags":["sonarqube","user-management","database"],"backgroundTag":"internal-invariant-violation","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}