{"record":{"id":"c1b1d343c2fffebf","repo":"apache/shenyu","slug":"registry-id-is-already-exist","errorCode":null,"errorMessage":"registry_id is already exist","messagePattern":"registry_id is already exist","errorType":"exception","errorClass":"ShenyuAdminException","httpStatus":null,"severity":"error","filePath":"shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RegistryServiceImpl.java","lineNumber":89,"sourceCode":"        return RegistryTransfer.INSTANCE.mapToVo(registryMapper.selectById(id));\n    }\n\n    @Override\n    public RegistryVO findByRegistryId(final String registryId) {\n        return RegistryTransfer.INSTANCE.mapToVo(registryMapper.selectByRegistryId(registryId));\n    }\n\n    @Override\n    public List<RegistryVO> listAll() {\n        List<RegistryDO> registryDOS = registryMapper.selectAll();\n        return registryDOS.stream().map(RegistryTransfer.INSTANCE::mapToVo).collect(Collectors.toList());\n    }\n\n\n    private RegistryVO create(final RegistryDTO registryDTO) {\n        RegistryDO existRegistryDO = registryMapper.selectByRegistryId(registryDTO.getRegistryId());\n        if (Objects.nonNull(existRegistryDO)) {\n            throw new ShenyuAdminException(\"registry_id is already exist\");\n        }\n\n        Timestamp currentTime = new Timestamp(System.currentTimeMillis());\n        String id = UUIDUtils.getInstance().generateShortUuid();\n        RegistryDO registryDO = RegistryDO.builder()\n                .id(id)\n                .registryId(registryDTO.getRegistryId())\n                .protocol(registryDTO.getProtocol())\n                .address(registryDTO.getAddress())\n                .namespace(registryDTO.getNamespace())\n                .username(registryDTO.getUsername())\n                .password(registryDTO.getPassword())\n                .registryGroup(registryDTO.getGroup())\n                .dateCreated(currentTime)\n                .dateUpdated(currentTime)\n                .build();\n        registryMapper.insert(registryDO);\n","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RegistryServiceImpl.java#L71-L107","documentation":"Thrown by the private RegistryServiceImpl.create() when a registry config with the same registryId already exists. create() looks up registryMapper.selectByRegistryId() and throws ShenyuAdminException(\"registry_id is already exist\") to enforce registryId uniqueness, since createOrUpdate routes to create when no row id is supplied.","triggerScenarios":"Calling createOrUpdate with a RegistryDTO whose id is null but whose registryId already exists in the registry table — i.e. an 'insert' that collides with an existing registry identifier.","commonSituations":"Registering the same registry (e.g. same zookeeper/nacos address id) twice through the dashboard or REST API; re-running an init/import script that already created the registry.","solutions":["Query existing registries first; if the registryId exists, call createOrUpdate with the existing row's id so it takes the update path.","Catch ShenyuAdminException and treat it as idempotent success if the registryId is the one you intended.","Choose a different, unique registryId if you actually want a second registry entry.","Delete the stale registry entry before re-creating it with the same id."],"exampleFix":"// before\nRegistryDTO dto = new RegistryDTO();\ndto.setRegistryId(\"zk-registry\"); // id left null -> insert path\nregistryService.createOrUpdate(dto);\n\n// after\nRegistryDO existing = registryMapper.selectByRegistryId(\"zk-registry\");\nRegistryDTO dto = new RegistryDTO();\ndto.setRegistryId(\"zk-registry\");\nif (existing != null) {\n    dto.setId(existing.getId()); // route to update path\n}\nregistryService.createOrUpdate(dto);","handlingStrategy":"validation","validationCode":"if (registryMapper.selectByRegistryId(dto.getRegistryId()) != null) {\n    // route to update (set dto.id) or reject before calling createOrUpdate\n}","typeGuard":null,"tryCatchPattern":"try {\n    registryService.createOrUpdate(dto);\n} catch (ShenyuAdminException e) {\n    if (\"registry_id is already exist\".equals(e.getMessage())) { /* fetch existing by registryId and update instead */ } else { throw e; }\n}","preventionTips":["Always look up the registry by registryId before insert.","Reuse the existing row's id to take the update path for idempotent upserts.","Use unique, descriptive registryIds per environment.","Make import scripts re-runnable by checking existence first."],"tags":["duplicate-record","admin-api","registry","uniqueness"],"backgroundTag":"file-already-exists","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}