{"record":{"id":"46c1fe2adb9bc26a","repo":"apache/shenyu","slug":"namespace-is-not-exist-namespaceserviceimpl","errorCode":null,"errorMessage":"namespace is not exist","messagePattern":"namespace is not exist","errorType":"exception","errorClass":"ShenyuAdminException","httpStatus":null,"severity":"error","filePath":"shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespaceServiceImpl.java","lineNumber":226,"sourceCode":"        String namespaceId = StringUtils.defaultString(namespaceDTO.getNamespaceId(), NamespaceIDUtils.getInstance().generateNamespaceID());\n        NamespaceDO namespaceDO = NamespaceDO.builder()\n                .id(id)\n                .namespaceId(namespaceId)\n                .name(namespaceDTO.getName())\n                .description(namespaceDTO.getDescription())\n                .dateCreated(currentTime)\n                .dateUpdated(currentTime)\n                .build();\n        namespaceMapper.insert(namespaceDO);\n\n        namespaceEventPublisher.publish(new NamespaceCreatedEvent(namespaceDO, SessionUtil.visitorId()));\n\n        return NamespaceTransfer.INSTANCE.mapToVo(namespaceDO);\n    }\n\n    private NamespaceVO update(final NamespaceDTO namespaceDTO) {\n        if (Objects.isNull(namespaceDTO) || Objects.isNull(namespaceDTO.getNamespaceId())) {\n            throw new ShenyuAdminException(\"namespace is not exist\");\n        }\n        Timestamp currentTime = new Timestamp(System.currentTimeMillis());\n        NamespaceDO namespaceDO = NamespaceDO.builder()\n                .namespaceId(namespaceDTO.getNamespaceId())\n                .name(namespaceDTO.getName())\n                .description(namespaceDTO.getDescription())\n                .dateUpdated(currentTime)\n                .build();\n        return namespaceMapper.updateSelective(namespaceDO) > 0\n                ? NamespaceTransfer.INSTANCE.mapToVo(namespaceDO) : null;\n    }\n}\n","sourceCodeStart":208,"sourceCodeEnd":239,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespaceServiceImpl.java#L208-L239","documentation":"NamespaceServiceImpl.update requires a NamespaceDTO carrying a namespaceId to identify the row to modify. When the DTO is null or its namespaceId is null, the method throws \"namespace is not exist\" because it cannot locate or address any existing namespace to update.","triggerScenarios":"Calling createOrUpdate (which delegates to private update) with a NamespaceDTO that is null, or a NamespaceDTO whose getNamespaceId() returns null — e.g. building the DTO without setting namespaceId, or deserializing a request body missing the namespaceId field.","commonSituations":"Dashboard/API clients sending an update payload without namespaceId; code that reuses a creation-style DTO (no id) for updates; deserialization dropping the id field due to renamed/mismatched JSON keys after a version upgrade.","solutions":["Set namespaceId on the NamespaceDTO before calling createOrUpdate/update","Ensure the HTTP request body includes the namespaceId field with the exact expected key","Verify the client is targeting an existing namespace and passing its identifier, not a fresh DTO","Null-check the DTO and its namespaceId at the controller/caller level to fail with a clearer validation message"],"exampleFix":"// before\nNamespaceDTO dto = new NamespaceDTO();\ndto.setName(\"prod\");\nnamespaceService.createOrUpdate(dto); // throws: namespace is not exist\n// after\nNamespaceDTO dto = new NamespaceDTO();\ndto.setNamespaceId(\"2a4d1c9f-ns-id\"); // existing namespace identifier\ndto.setName(\"prod\");\nnamespaceService.createOrUpdate(dto);","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(namespaceDTO, \"namespaceDTO must not be null\");\nObjects.requireNonNull(namespaceDTO.getNamespaceId(), \"namespaceId is required for update\");\nnamespaceService.createOrUpdate(namespaceDTO);","typeGuard":"boolean isUpdatable(NamespaceDTO dto) {\n    return dto != null && dto.getNamespaceId() != null && !dto.getNamespaceId().isEmpty();\n}","tryCatchPattern":"try {\n    namespaceService.createOrUpdate(namespaceDTO);\n} catch (ShenyuAdminException e) {\n    if (\"namespace is not exist\".equals(e.getMessage())) {\n        throw new IllegalArgumentException(\"namespaceId is required to update a namespace\", e);\n    }\n    throw e;\n}","preventionTips":["Always populate namespaceId when constructing a NamespaceDTO for updates","Validate the update payload at the controller layer before invoking the service","Distinguish create vs update flows: only updates require a pre-existing namespaceId","After version upgrades, verify request body field names still map to namespaceId"],"tags":["shenyu","admin","namespace","null-argument","validation"],"backgroundTag":"missing-required-argument","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"}