{"record":{"id":"ec8acd03e92e1876","repo":"theonedev/onedev","slug":"name-already-used-by-another-access-token-of-the-o","errorCode":null,"errorMessage":"Name already used by another access token of the owner","messagePattern":"Name already used by another access token of the owner","errorType":"http","errorClass":"ExplicitException","httpStatus":400,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/AccessTokenResource.java","lineNumber":79,"sourceCode":"\t@GET\n\tpublic Collection<AccessTokenAuthorization> getAuthorizations(@PathParam(\"accessTokenId\") Long accessTokenId) {\n\t\tvar accessToken = accessTokenService.load(accessTokenId);\n\t\tif (!isAdministrator() && !accessToken.getOwner().equals(getAuthUser()))\n\t\t\tthrow new UnauthorizedException();\n\t\treturn accessToken.getAuthorizations();\n\t}\n\t\n\t@Api(order=200, description=\"Create access token\")\n\t@POST\n\tpublic Long createToken(@NotNull @Valid AccessToken accessToken) {\n\t\tvar owner = accessToken.getOwner();\n\t\tif (!isAdministrator() && !owner.equals(getAuthUser()))\n\t\t\tthrow new UnauthorizedException();\n\t\telse if (owner.isDisabled())\n\t\t\tthrow new ExplicitException(\"Cannot create access token for disabled user\");\n\t\t\n\t\tif (accessTokenService.findByOwnerAndName(owner, accessToken.getName()) != null)\n\t\t\tthrow new ExplicitException(\"Name already used by another access token of the owner\");\n\t\t\t\n\t\taccessTokenService.createOrUpdate(accessToken);\n\n\t\tif (!getAuthUser().equals(owner)) {\n\t\t\tvar newAuditContent = VersionedXmlDoc.fromBean(accessToken.getFacade()).toXML();\n\t\t\tauditService.audit(null, \"created access token \\\"\" + accessToken.getName() + \"\\\" in account \\\"\" + owner.getName() + \"\\\" via RESTful API\", \n\t\t\t\t\tnull, newAuditContent);\n\t\t}\n\n\t\treturn accessToken.getId();\n\t}\n\n\t@Api(order=250, description=\"Update access token\")\n\t@Path(\"/{accessTokenId}\")\n\t@POST\n\tpublic Response updateToken(@PathParam(\"accessTokenId\") Long accessTokenId, @NotNull @Valid AccessToken accessToken) {\n\t\tvar owner = accessToken.getOwner();\n\t\tif (!isAdministrator() && !owner.equals(getAuthUser()))","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/AccessTokenResource.java#L61-L97","documentation":"createToken throws ExplicitException when the requested token name is already used by another access token belonging to the same owner. Token names must be unique per owner, enforced via accessTokenService.findByOwnerAndName().","triggerScenarios":"POST /~access-tokens (AccessTokenResource.createToken) where findByOwnerAndName(owner, accessToken.getName()) returns non-null — a token with the same name already exists for that owner.","commonSituations":"Re-running idempotent provisioning scripts without unique names; re-creating a token after deletion failed or used a different owner; users unaware of an existing token with the same name created earlier.","solutions":["Pick a different, unique token name for that owner.","Delete or rename the existing token with the same name first, then retry.","Generate names programmatically (e.g., include a timestamp) in automation scripts.","Check the existing token list for the owner before creating."],"exampleFix":"// before\n{\"name\": \"ci-token\", ...}  // 'ci-token' already exists for this owner\n// after\n{\"name\": \"ci-token-2026-09\", ...}","handlingStrategy":"validation","validationCode":"const existing = await listOwnerTokens(ownerName);\nif (existing.some(t => t.name === desiredName)) {\n  throw new Error(`Token name '${desiredName}' already used for owner ${ownerName}`);\n}","typeGuard":"function nameIsFree(existingNames: string[], name: string): boolean {\n  return !existingNames.includes(name);\n}","tryCatchPattern":"try {\n  await createToken(payload);\n} catch (e) {\n  if (/Name already used/.test(String(e.response?.data?.message ?? e.message))) {\n    payload.name = `${payload.name}-${Date.now()}`;\n    await createToken(payload);\n  } else throw e;\n}","preventionTips":["Uniquify token names in automation (timestamps, run ids)","Delete stale tokens before reusing their names","Maintain a naming convention per owner"],"tags":["rest","access-token","naming-conflict"],"backgroundTag":"duplicate-resource-name","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"}