{"record":{"id":"7f27c48dd06ed8d2","repo":"apache/pulsar","slug":"invalid-namespace-format-namespace-s-s","errorCode":null,"errorMessage":"Invalid namespace format. namespace: %s/%s","messagePattern":"Invalid namespace format\\. namespace: (.+?)/(.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-common/src/main/java/org/apache/pulsar/common/naming/NamespaceName.java","lineNumber":163,"sourceCode":"\n    @Override\n    public boolean equals(Object obj) {\n        if (obj instanceof NamespaceName) {\n            NamespaceName other = (NamespaceName) obj;\n            return Objects.equals(namespace, other.namespace);\n        }\n\n        return false;\n    }\n\n    @Override\n    public int hashCode() {\n        return namespace.hashCode();\n    }\n\n    public static void validateNamespaceName(String tenant, String namespace) {\n        if ((tenant == null || tenant.isEmpty()) || (namespace == null || namespace.isEmpty())) {\n            throw new IllegalArgumentException(\n                    String.format(\"Invalid namespace format. namespace: %s/%s\", tenant, namespace));\n        }\n        NamedEntity.checkName(tenant);\n        NamedEntity.checkName(namespace);\n    }\n\n    @Override\n    public NamespaceName getNamespaceObject() {\n        return this;\n    }\n\n    @Override\n    public boolean includes(TopicName topicName) {\n        return this.equals(topicName.getNamespaceObject());\n    }\n}\n","sourceCodeStart":145,"sourceCodeEnd":180,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-common/src/main/java/org/apache/pulsar/common/naming/NamespaceName.java#L145-L180","documentation":"NamespaceName.validateNamespaceName(tenant, namespace) validates the two components of a V2 namespace name. It throws this IllegalArgumentException when either the tenant or the namespace part is null or empty, formatting them as 'tenant/namespace' in the message. After the null/empty check it also runs NamedEntity.checkName on both parts.","triggerScenarios":"Calling NamespaceName.get(tenant, namespace) with null or empty tenant, or null or empty namespace — e.g. NamespaceName.get(null, \"default\") or NamespaceName.get(\"public\", \"\"). Also triggered from the NamespaceName(String) parsing path when a segment of a 'a/b' name is empty (e.g. 'public/' or '/default').","commonSituations":"Configuration where tenant or namespace keys are unset and default to empty strings; splitting a namespace string that has an empty segment; templated service URLs where variables were not substituted; programmatic client construction with unset builder fields.","solutions":["Supply both a non-null, non-empty tenant and namespace, e.g. NamespaceName.get(\"public\", \"default\").","Trim/normalize inputs from config and treat empty strings as missing values before constructing.","If components come from splitting a string, verify the string contains a non-empty segment on each side of '/'.","Use NamespaceName.isValid or try-catch around construction when input origin is untrusted."],"exampleFix":"// before\nString tenant = config.get(\"tenant\"); // \"\"\nNamespaceName ns = NamespaceName.get(tenant, \"default\");\n// after\nString tenant = config.get(\"tenant\");\nNamespaceName ns = (tenant == null || tenant.isEmpty())\n        ? NamespaceName.get(\"public\", \"default\")\n        : NamespaceName.get(tenant, \"default\");","handlingStrategy":"validation","validationCode":"void requireNonEmpty(String v, String what) {\n    if (v == null || v.isEmpty()) {\n        throw new IllegalArgumentException(what + \" must be non-empty\");\n    }\n}\n// call before: requireNonEmpty(tenant, \"tenant\"); requireNonEmpty(localName, \"namespace\");\nNamespaceName.validateNamespaceName(tenant, localName);","typeGuard":"static boolean hasValidComponents(String tenant, String ns) {\n    return tenant != null && !tenant.isEmpty() && ns != null && !ns.isEmpty();\n}","tryCatchPattern":"try {\n    NamespaceName.validateNamespaceName(tenant, localName);\n} catch (IllegalArgumentException e) {\n    throw new IllegalArgumentException(\"Both tenant and namespace must be non-empty; got tenant='\" + tenant + \"' namespace='\" + localName + \"'\", e);\n}","preventionTips":["Normalize empty config strings to null and fail with a clear message naming the missing key.","Call validateNamespaceName proactively in admin/CLI layers before any API call.","When splitting 'a/b' strings, use split(\"/\", -1) and reject empty segments explicitly."],"tags":["pulsar","namespace","validation","illegal-argument"],"backgroundTag":"invalid-namespace-format","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}