theonedev/onedev · error · NotAcceptableException
Login name is already used by another user
Error message
Login name is already used by another user
What it means
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.
Source
Thrown at server-core/src/main/java/io/onedev/server/rest/resource/UserResource.java:360
public Long getUserId(@PathParam("name") @Api(description = "Login name of user") String name) {
if (SecurityUtils.getAuthUser() == null)
throw new UnauthenticatedException();
var user = userService.findByName(name);
if (user != null)
return user.getId();
else
throw new NotFoundException();
}
@Api(order=1900, description="Create new user")
@POST
public Long createUser(@NotNull @Valid UserCreateData data) {
if (!SecurityUtils.isAdministrator())
throw new UnauthorizedException();
if (userService.findByName(data.getName()) != null)
throw new NotAcceptableException("Login name is already used by another user");
if (data.getType() == ORDINARY && emailAddressService.findByValue(data.getEmailAddress()) != null)
throw new NotAcceptableException("Email address is already used by another user");
User user = new User();
user.setType(data.getType());
user.setName(data.getName());
user.setFullName(data.getFullName());
if (data.getType() == AI)
user.setAiSetting(data.getAiSetting());
if (data.getType() != ORDINARY) {
userService.create(user);
} else {
user.setNotifyOwnEvents(data.isNotifyOwnEvents());
user.setPassword(passwordService.encryptPassword(data.getPassword()));
userService.create(user);
EmailAddress emailAddress = new EmailAddress();
emailAddress.setPrimary(true);View on GitHub (pinned to d44925c47c)
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.
Example fix
// before
client.createUser(new UserCreateData("alice", "alice@corp.com", ORDINARY)); // may 406 if exists
// after
Long existing = client.findUserId("alice");
if (existing == null)
client.createUser(new UserCreateData("alice", "alice@corp.com", ORDINARY)); Defensive patterns
Strategy: validation
Validate before calling
boolean exists = client.findUserId(data.getName()) != null;
if (exists) { log.info("User " + data.getName() + " already exists; skipping"); return; } Try / catch
try { return client.createUser(data); }
catch (NotAcceptableException e) {
if (e.getMessage().contains("already used")) return client.findUserId(data.getName());
throw e;
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: Idempotency-unaware provisioning scripts run twice; importing users where case variants of a name collide; seed data conflicting with manually created users.
Related errors
- Email address is already used by another user
- Unauthenticated
- Multiple users found: ${userName}
- User not found: ${userName}
- Count should not be greater than ${RestConstants.MAX_PAGE_SI
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/1fc909a5aa7acbfc.
Report an issue: GitHub.