{"record":{"id":"2dcb58649e54cf10","repo":"theonedev/onedev","slug":"this-email-address-is-already-used-by-another-user","errorCode":null,"errorMessage":"This email address is already used by another user","messagePattern":"This 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/EmailAddressResource.java","lineNumber":83,"sourceCode":"    \tif (!SecurityUtils.isAdministrator() && !emailAddress.getOwner().equals(getAuthUser())) \n\t\t\tthrow new UnauthorizedException();\n    \treturn emailAddress.isVerified();\n\t}\n\t\n\t@Api(order=200, description=\"Create new email address\")\n\t@POST\n\tpublic Long createEmailAddress(@NotNull @Valid EmailAddress emailAddress) {\n\t\tvar owner = emailAddress.getOwner();\n\t\tif (!SecurityUtils.isAdministrator() && !owner.equals(getAuthUser()))\n\t\t\tthrow new UnauthorizedException();\n\t\telse if (owner.isDisabled())\n\t\t\tthrow new NotAcceptableException(\"Cannot set email address for disabled user\");\n\t\telse if (owner.getType() != User.Type.ORDINARY)\n\t\t\tthrow new NotAcceptableException(\"Cannot set email address for service or ai user\");\n\t\telse if (User.getLoginName(emailAddress.getValue()) != null)\n\t\t\tthrow new NotAcceptableException(\"Email address with noreply domain is not allowed\");\n\t\telse if (emailAddressService.findByValue(emailAddress.getValue()) != null)\n\t\t\tthrow new NotAcceptableException(\"This email address is already used by another user\");\n\t\t\n\t\tif (SecurityUtils.isAdministrator()) \n\t\t\temailAddress.setVerificationCode(null);\n\t\t\n\t\temailAddressService.create(emailAddress);\n\n\t\tif (!getAuthUser().equals(owner)) \n\t\t\tauditService.audit(null, \"added email address \\\"\" + emailAddress.getValue() + \"\\\" in account \\\"\" + owner.getName() + \"\\\" via RESTful API\", null, null);\n\t\treturn emailAddress.getId();\n\t}\n\t\n\t@Api(order=250, description=\"Set as primary email address\")\n\t@Path(\"/primary\")\n\t@POST\n\tpublic Long setAsPrimary(@NotNull Long emailAddressId) {\n\t\tvar emailAddress = emailAddressService.load(emailAddressId);\n\t\tvar owner = emailAddress.getOwner();\n\t\tif (!SecurityUtils.isAdministrator() && !owner.equals(getAuthUser()))","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/EmailAddressResource.java#L65-L101","documentation":"Each email address value must be unique across all OneDev users. If emailAddressService.findByValue(value) already returns an address, the endpoint rejects creation with NotAcceptableException to prevent duplicate address ownership.","triggerScenarios":"POST an EmailAddress whose value is already registered to any user (including the same user), or re-running a provisioning script that already created the address.","commonSituations":"Idempotency-unaware automation run twice; shared corporate addresses assigned to two accounts; a user re-adding an address they already have via a different flow.","solutions":["Check emailAddressService.findByValue(value) first and reuse/update the existing record instead of creating","Make provisioning scripts idempotent (lookup before create)","Choose a different, unused email value"],"exampleFix":"// before\nemailAddressService.create(newAddressWithValue(value));\n// after\nEmailAddress existing = emailAddressService.findByValue(value);\nif (existing == null) emailAddressService.create(newAddressWithValue(value));","handlingStrategy":"validation","validationCode":"if (emailAddressService.findByValue(value) != null) reuse existing instead of create;","typeGuard":"boolean free = emailAddressService.findByValue(value) == null;","tryCatchPattern":"try { createEmailAddress(ea); } catch (NotAcceptableException e) { /* duplicate: lookup and update existing */ }","preventionTips":["Lookup before create in all provisioning code","Make scripts idempotent","Enforce address uniqueness in upstream systems"],"tags":["rest-api","duplicate","email","onedev"],"backgroundTag":"file-already-exists","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}