{"record":{"id":"1fc909a5aa7acbfc","repo":"theonedev/onedev","slug":"login-name-is-already-used-by-another-user","errorCode":null,"errorMessage":"Login name is already used by another user","messagePattern":"Login name is already used by another user","errorType":"http","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/UserResource.java","lineNumber":360,"sourceCode":"\tpublic Long getUserId(@PathParam(\"name\") @Api(description = \"Login name of user\") String name) {\n\t\tif (SecurityUtils.getAuthUser() == null)\n\t\t\tthrow new UnauthenticatedException();\n\n\t\tvar user = userService.findByName(name);\n\t\tif (user != null)\n\t\t\treturn user.getId();\n\t\telse \n\t\t\tthrow new NotFoundException();\n\t}\n\t\n\t@Api(order=1900, description=\"Create new user\")\n    @POST\n    public Long createUser(@NotNull @Valid UserCreateData data) {\n\t\tif (!SecurityUtils.isAdministrator()) \n\t\t\tthrow new UnauthorizedException();\n\n\t\tif (userService.findByName(data.getName()) != null)\n\t\t\tthrow new NotAcceptableException(\"Login name is already used by another user\");\n\t\tif (data.getType() == ORDINARY && emailAddressService.findByValue(data.getEmailAddress()) != null)\n\t\t\tthrow new NotAcceptableException(\"Email address is already used by another user\");\n\t\t\n\t\tUser user = new User();\n\t\tuser.setType(data.getType());\n\t\tuser.setName(data.getName());\n\t\tuser.setFullName(data.getFullName());\n\t\tif (data.getType() == AI) \n\t\t\tuser.setAiSetting(data.getAiSetting());\n\t\t\n\t\tif (data.getType() != ORDINARY) {\n\t\t\tuserService.create(user);\n\t\t} else {\n\t\t\tuser.setNotifyOwnEvents(data.isNotifyOwnEvents());\n\t\t\tuser.setPassword(passwordService.encryptPassword(data.getPassword()));\n\t\t\tuserService.create(user);\n\t\t\tEmailAddress emailAddress = new EmailAddress();\n\t\t\temailAddress.setPrimary(true);","sourceCodeStart":342,"sourceCodeEnd":378,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/UserResource.java#L342-L378","documentation":"Thrown by UserResource.createUser when the login name in the POST /rest/users payload is already taken by an existing user. OneDev enforces globally unique login names; the REST layer checks userService.findByName before creating the account.","triggerScenarios":"POST /rest/users with UserCreateData whose name matches an existing user's login name (or a re-run of a creation script that already succeeded).","commonSituations":"Idempotency-unaware provisioning scripts run twice; importing users where case variants of a name collide; seed data conflicting with manually created users.","solutions":["Check existence first via GET /users/ids/{name} and skip creation if found.","Choose a different login name in the payload.","Make the provisioning script idempotent (lookup-then-create or upsert).","Delete or rename the conflicting user if it is stale."],"exampleFix":"// before\nclient.createUser(new UserCreateData(\"alice\", \"alice@corp.com\", ORDINARY)); // may 406 if exists\n// after\nLong existing = client.findUserId(\"alice\");\nif (existing == null)\n    client.createUser(new UserCreateData(\"alice\", \"alice@corp.com\", ORDINARY));","handlingStrategy":"validation","validationCode":"boolean exists = client.findUserId(data.getName()) != null;\nif (exists) { log.info(\"User \" + data.getName() + \" already exists; skipping\"); return; }","typeGuard":null,"tryCatchPattern":"try { return client.createUser(data); }\ncatch (NotAcceptableException e) {\n    if (e.getMessage().contains(\"already used\")) return client.findUserId(data.getName());\n    throw e;\n}","preventionTips":["Make provisioning scripts idempotent: lookup before create.","Normalize login names (case) before checking uniqueness.","Use a single source of truth for user names to avoid collisions."],"tags":["rest","duplicate","user-creation"],"backgroundTag":"resource-already-exists","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}