{"record":{"id":"28913da9f08454cd","repo":"apache/pulsar","slug":"namespace-name-is-not-valid","errorCode":null,"errorMessage":"Namespace name is not valid","messagePattern":"Namespace name is not valid","errorType":"http","errorClass":"org.apache.pulsar.broker.admin.RestException","httpStatus":412,"severity":"error","filePath":"pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java","lineNumber":216,"sourceCode":"                                .log(\"Fail to create topic partition\");\n                        result.completeExceptionally(ex.getCause());\n                    }\n                    return null;\n                });\n        pulsar().getBrokerService().getTopicEventsDispatcher()\n                .notifyOnCompletion(result, topicName.getPartition(partition).toString(), TopicEvent.CREATE);\n        return result;\n    }\n\n    protected void validateNamespaceName(String tenant, String namespace) {\n        try {\n            this.namespaceName = NamespaceName.get(tenant, namespace);\n        } catch (IllegalArgumentException e) {\n            log.warn()\n                    .attr(\"tenant\", tenant)\n                    .attr(\"namespace\", namespace)\n                    .log(\"Invalid namespace name\");\n            throw new RestException(Status.PRECONDITION_FAILED, \"Namespace name is not valid\");\n        }\n    }\n\n    protected void validateGlobalNamespaceOwnership() {\n        try {\n            validateGlobalNamespaceOwnership(this.namespaceName);\n        } catch (IllegalArgumentException e) {\n            throw new RestException(Status.PRECONDITION_FAILED, \"Tenant name or namespace is not valid\");\n        } catch (RestException re) {\n            throw re;\n        } catch (Exception e) {\n            log.warn()\n                    .attr(\"namespace\", namespaceName)\n                    .exceptionMessage(e)\n                    .log(\"Failed to validate global cluster configuration\");\n            throw new RestException(Status.SERVICE_UNAVAILABLE, \"Failed to validate global cluster configuration\");\n        }\n    }","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java#L198-L234","documentation":"AdminResource.validateNamespaceName parses tenant and namespace components into a NamespaceName. If the combination violates namespace naming rules, NamespaceName.get throws IllegalArgumentException, which is converted to HTTP 412 'Namespace name is not valid'. Valid namespace names are tenant/localName where localName is up to 255 chars with allowed characters [a-zA-Z0-9_.-].","triggerScenarios":"Any admin API call carrying a namespace identifier whose local name is empty, longer than 255 characters, or contains characters outside [a-zA-Z0-9_.-] (e.g. 'my ns', 'ns!', or a trailing slash producing an empty segment).","commonSituations":"URL-encoding mishaps where spaces or special characters reach the broker; scripts interpolating empty namespace variables; auto-generated namespace names from user input or UUIDs containing invalid characters; copy-paste errors including extra slashes.","solutions":["Use a namespace local name matching [a-zA-Z0-9_.-]+ (max 255 chars), e.g. tenant/ns1.","Escape/validate the namespace in client scripts before building the admin URL.","If names come from user input, sanitize or reject invalid characters at your application's edge.","Check for double slashes or empty segments in the request path."],"exampleFix":"// before\nString ns = userInput.get(\"namespace\"); // \"my ns!\"\nadmin.namespaces().createNamespace(tenant + \"/\" + ns);\n\n// after\nString ns = userInput.get(\"namespace\");\nif (!ns.matches(\"[a-zA-Z0-9_.-]+\")) {\n    throw new IllegalArgumentException(\"invalid namespace name\");\n}\nadmin.namespaces().createNamespace(tenant + \"/\" + ns);","handlingStrategy":"validation","validationCode":"boolean isValidNamespaceName(String tenant, String namespace) {\n    return tenant != null && tenant.matches(\"[a-zA-Z0-9_.-]+\")\n        && namespace != null && namespace.matches(\"[a-zA-Z0-9_.-]+\")\n        && namespace.length() <= 255;\n}","typeGuard":"String requireValidNamespace(String tenantSlashNamespace) {\n    String[] parts = tenantSlashNamespace.split(\"/\", -1);\n    if (parts.length != 2 || !isValidNamespaceName(parts[0], parts[1])) {\n        throw new IllegalArgumentException(\"invalid namespace name: \" + tenantSlashNamespace);\n    }\n    return tenantSlashNamespace;\n}","tryCatchPattern":"try {\n    admin.namespaces().createNamespace(ns);\n} catch (PulsarAdminException e) {\n    if (e.getStatusCode() == 412 && e.getMessage().contains(\"Namespace name is not valid\")) {\n        log.error(\"Namespace '{}' violates Pulsar naming rules [a-zA-Z0-9_.-]\", ns);\n    }\n}","preventionTips":["Validate namespace names against [a-zA-Z0-9_.-]+ and 255-char limit before API calls","Sanitize user/auto-generated namespace inputs","URL-encode names in REST calls and avoid extra slashes"],"tags":["admin-api","validation","namespace","naming"],"backgroundTag":"invalid-resource-name","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}