{"record":{"id":"a1c764d7dcbd10d2","repo":"theonedev/onedev","slug":"email-address-is-already-used-by-another-user","errorCode":null,"errorMessage":"Email address is already used by another user","messagePattern":"Email address 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":362,"sourceCode":"\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);\n\t\t\temailAddress.setOwner(user);\n\t\t\temailAddress.setValue(data.getEmailAddress());","sourceCodeStart":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/UserResource.java#L344-L380","documentation":"Thrown by UserResource.createUser when the email address in the payload is already associated with another user. For ordinary users (type ORDINARY), OneDev requires unique email addresses, checked via emailAddressService.findByValue.","triggerScenarios":"POST /rest/users with UserCreateData of type ORDINARY whose emailAddress is already registered to any user (only ORDINARY users are checked, so AI/robot types bypass this).","commonSituations":"Reusing a shared mailbox for multiple accounts; re-running import scripts; creating a user with the email of a previously deactivated user.","solutions":["Use an unused email address for the new account.","Look up which user owns the email and update that user instead.","If the account is a bot, set type to AI instead of ORDINARY to skip the email-uniqueness check.","Clean up the stale user holding the email if appropriate."],"exampleFix":"// before\nUserCreateData d = new UserCreateData(\"bob2\", \"bob@corp.com\", ORDINARY); // bob@corp.com taken\n// after\nUserCreateData d = new UserCreateData(\"bob2\", \"bob2@corp.com\", ORDINARY); // unique email\n// or for bots:\nUserCreateData bot = new UserCreateData(\"ci-bot\", \"bob@corp.com\", AI);","handlingStrategy":"validation","validationCode":"if (data.getType() == ORDINARY && client.emailInUse(data.getEmailAddress()))\n    throw new IllegalArgumentException(\"Email \" + data.getEmailAddress() + \" already registered\");","typeGuard":null,"tryCatchPattern":"try { return client.createUser(data); }\ncatch (NotAcceptableException e) {\n    if (e.getMessage().contains(\"Email address\")) throw new DuplicateEmailException(e);\n    throw e;\n}","preventionTips":["Maintain a unique-email constraint in your user directory before syncing.","Use AI/robot type for service accounts to bypass ordinary-user email checks where appropriate.","Check for stale users holding old emails during imports."],"tags":["rest","duplicate","email","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"}