{"record":{"id":"01c45e7c4d3a20bd","repo":"apache/pulsar","slug":"invalid-null-namespace-namespace","errorCode":null,"errorMessage":"Invalid null namespace: ${namespace}","messagePattern":"Invalid null namespace: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-common/src/main/java/org/apache/pulsar/common/naming/NamespaceName.java","lineNumber":58,"sourceCode":"\n    private static final LoadingCache<String, NamespaceName> cache = CacheBuilder.newBuilder().maximumSize(100000)\n            .expireAfterAccess(30, TimeUnit.MINUTES).build(new CacheLoader<String, NamespaceName>() {\n                @Override\n                public NamespaceName load(String name) throws Exception {\n                    return new NamespaceName(name);\n                }\n            });\n\n    public static final NamespaceName SYSTEM_NAMESPACE = NamespaceName.get(\"pulsar/system\");\n\n    public static NamespaceName get(String tenant, String namespace) {\n        validateNamespaceName(tenant, namespace);\n        return get(tenant + '/' + namespace);\n    }\n\n    public static NamespaceName get(String namespace) {\n        if (namespace == null || namespace.isEmpty()) {\n            throw new IllegalArgumentException(\"Invalid null namespace: \" + namespace);\n        }\n        try {\n            return cache.get(namespace);\n        } catch (ExecutionException e) {\n            throw (RuntimeException) e.getCause();\n        } catch (UncheckedExecutionException e) {\n            throw (RuntimeException) e.getCause();\n        }\n    }\n\n    public static Optional<NamespaceName> getIfValid(String namespace) {\n        NamespaceName ns = cache.getIfPresent(namespace);\n        if (ns != null) {\n            return Optional.of(ns);\n        }\n\n        if (namespace.length() == 0) {\n            return Optional.empty();","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-common/src/main/java/org/apache/pulsar/common/naming/NamespaceName.java#L40-L76","documentation":"NamespaceName.get(String) rejects null or empty namespace strings with IllegalArgumentException before consulting the cache. The namespace string must be a non-empty 'tenant/namespace' (or legacy V1) path.","triggerScenarios":"Calling NamespaceName.get(null) or NamespaceName.get(\"\") directly, or via the two-argument get(tenant, namespace) where either component is null/empty; also hit by tests like testPushGetAndRemove that probe this path.","commonSituations":"Parsing topic URLs where the namespace segment is missing (e.g. 'persistent://tenant//topic'), config values left blank, split() producing empty components.","solutions":["Check the namespace string is non-null and non-empty before calling NamespaceName.get","Fix upstream URL/config parsing so the tenant and namespace segments are populated","Provide a default namespace when the caller's value may be absent"],"exampleFix":"// before\nNamespaceName ns = NamespaceName.get(cfg.get(\"namespace\")); // may be null\n// after\nString nsStr = cfg.get(\"namespace\");\nif (nsStr == null || nsStr.isEmpty()) { nsStr = \"public/default\"; }\nNamespaceName ns = NamespaceName.get(nsStr);","handlingStrategy":"type-guard","validationCode":"boolean validNamespace(String ns) {\n    return ns != null && !ns.isEmpty() && ns.contains(\"/\") && !ns.startsWith(\"/\") && !ns.endsWith(\"/\");\n}","typeGuard":"Optional<NamespaceName> tryGetNamespace(String ns) {\n    if (ns == null || ns.isEmpty()) {\n        return Optional.empty();\n    }\n    try {\n        return Optional.of(NamespaceName.get(ns));\n    } catch (IllegalArgumentException e) {\n        return Optional.empty();\n    }\n}","tryCatchPattern":"try {\n    NamespaceName ns = NamespaceName.get(namespace);\n} catch (IllegalArgumentException e) {\n    throw new IllegalArgumentException(\"Namespace must be non-empty '<tenant>/<namespace>', got: \" + namespace, e);\n}","preventionTips":["Validate URL/config parsing output before constructing NamespaceName","Default to 'public/default' when a namespace value is absent","Check for empty segments when splitting topic URLs on '/'"],"tags":["namespace","validation","null-check","pulsar-common"],"backgroundTag":"invalid-null-namespace","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"}