theonedev/onedev · error · NotAcceptableException
This email address is already used by another user
Error message
This email address is already used by another user
What it means
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.
Source
Thrown at server-core/src/main/java/io/onedev/server/rest/resource/EmailAddressResource.java:83
if (!SecurityUtils.isAdministrator() && !emailAddress.getOwner().equals(getAuthUser()))
throw new UnauthorizedException();
return emailAddress.isVerified();
}
@Api(order=200, description="Create new email address")
@POST
public Long createEmailAddress(@NotNull @Valid EmailAddress emailAddress) {
var owner = emailAddress.getOwner();
if (!SecurityUtils.isAdministrator() && !owner.equals(getAuthUser()))
throw new UnauthorizedException();
else if (owner.isDisabled())
throw new NotAcceptableException("Cannot set email address for disabled user");
else if (owner.getType() != User.Type.ORDINARY)
throw new NotAcceptableException("Cannot set email address for service or ai user");
else if (User.getLoginName(emailAddress.getValue()) != null)
throw new NotAcceptableException("Email address with noreply domain is not allowed");
else if (emailAddressService.findByValue(emailAddress.getValue()) != null)
throw new NotAcceptableException("This email address is already used by another user");
if (SecurityUtils.isAdministrator())
emailAddress.setVerificationCode(null);
emailAddressService.create(emailAddress);
if (!getAuthUser().equals(owner))
auditService.audit(null, "added email address \"" + emailAddress.getValue() + "\" in account \"" + owner.getName() + "\" via RESTful API", null, null);
return emailAddress.getId();
}
@Api(order=250, description="Set as primary email address")
@Path("/primary")
@POST
public Long setAsPrimary(@NotNull Long emailAddressId) {
var emailAddress = emailAddressService.load(emailAddressId);
var owner = emailAddress.getOwner();
if (!SecurityUtils.isAdministrator() && !owner.equals(getAuthUser()))View on GitHub (pinned to d44925c47c)
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
Example fix
// before emailAddressService.create(newAddressWithValue(value)); // after EmailAddress existing = emailAddressService.findByValue(value); if (existing == null) emailAddressService.create(newAddressWithValue(value));
Defensive patterns
Strategy: validation
Validate before calling
if (emailAddressService.findByValue(value) != null) reuse existing instead of create;
Type guard
boolean free = emailAddressService.findByValue(value) == null;
Try / catch
try { createEmailAddress(ea); } catch (NotAcceptableException e) { /* duplicate: lookup and update existing */ } Prevention
- Lookup before create in all provisioning code
- Make scripts idempotent
- Enforce address uniqueness in upstream systems
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- Reviewer not found:
- Assignee not found:
- Not authenticated
- Unable to create issue from email as service desk is not ena
- Unauthorized
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/2dcb58649e54cf10.
Report an issue: GitHub.