{"record":{"id":"cb1fea95d055638f","repo":"alibaba/spring-ai-alibaba","slug":"appnameexists","errorCode":"AppNameExists","errorMessage":"App name already exists.","messagePattern":"App name already exists\\.","errorType":"error_code","errorClass":"BizException","httpStatus":400,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/service/impl/AppServiceImpl.java","lineNumber":101,"sourceCode":"\t\tthis.redisManager = redisManager;\n\t\tthis.referService = referService;\n\t}\n\n\t/**\n\t * Creates a new application with initial version\n\t * @param application Application details to create\n\t * @return ID of the created application\n\t */\n\t@Override\n\t@Transactional(rollbackFor = Exception.class)\n\tpublic String createApp(Application application) {\n\t\ttry {\n\t\t\tRequestContext context = RequestContextHolder.getRequestContext();\n\n\t\t\t// check if app name exists\n\t\t\tAppEntity entity = getAppByName(context.getWorkspaceId(), application.getName());\n\t\t\tif (entity != null) {\n\t\t\t\tthrow new BizException(ErrorCode.APP_NAME_EXISTS.toError());\n\t\t\t}\n\n\t\t\tString appId = IdGenerator.idStr();\n\t\t\t// insert application\n\t\t\tentity = BeanCopierUtils.copy(application, AppEntity.class);\n\t\t\tentity.setAppId(appId);\n\t\t\tentity.setStatus(AppStatus.DRAFT);\n\t\t\tentity.setWorkspaceId(context.getWorkspaceId());\n\t\t\tentity.setGmtCreate(new Date());\n\t\t\tentity.setGmtModified(new Date());\n\t\t\tentity.setCreator(context.getAccountId());\n\t\t\tentity.setModifier(context.getAccountId());\n\t\t\tthis.save(entity);\n\n\t\t\t// insert application version\n\t\t\tAppVersionEntity versionEntity = new AppVersionEntity();\n\t\t\tversionEntity.setAppId(appId);\n\t\t\tversionEntity.setWorkspaceId(context.getWorkspaceId());","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/service/impl/AppServiceImpl.java#L83-L119","documentation":"BizException with code AppNameExists thrown by AppServiceImpl.createApp when an app with the same name already exists in the caller's workspace (getAppByName returns non-null). The library enforces workspace-unique app names, so creation is rejected before insert.","triggerScenarios":"Calling createApp(application) whose name duplicates an existing app in the same workspace; retrying a create that partially succeeded; seeding scripts run twice.","commonSituations":"Bootstrap/config-as-code re-runs creating apps idempotently; two users creating the same app name concurrently; copying examples without renaming the app.","solutions":["Check name availability first via getAppByName (or a list call) and use a unique name.","Make creation idempotent: if the app already exists, fetch it instead of creating.","Append a unique suffix (workspace/user/timestamp) when auto-generating names."],"exampleFix":"// before\nappService.createApp(application); // may throw AppNameExists\n// after\nif (appService.getAppByName(workspaceId, application.getName()) == null) {\n    appService.createApp(application);\n} else {\n    application.setName(application.getName() + \"-\" + System.currentTimeMillis());\n    appService.createApp(application);\n}","handlingStrategy":"validation","validationCode":"if (appService.getAppByName(workspaceId, application.getName()) != null) {\n    application.setName(application.getName() + \"-\" + UUID.randomUUID().toString().substring(0, 8));\n}","typeGuard":null,"tryCatchPattern":"try { appService.createApp(application); } catch (BizException e) { if (\"AppNameExists\".equals(e.getCode())) { /* fetch existing or rename */ } else throw e; }","preventionTips":["Make create scripts idempotent: check existence before create.","Generate names with unique suffixes in automation.","Handle concurrent creates with a retry-and-fetch strategy."],"tags":["duplicate","uniqueness-constraint","app-management"],"backgroundTag":"file-already-exists","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}