{"record":{"id":"21a9f18b11a9c619","repo":"apache/pulsar","slug":"invalid-named-entity-name","errorCode":null,"errorMessage":"Invalid named entity: ${name}","messagePattern":"Invalid named entity: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-common/src/main/java/org/apache/pulsar/common/naming/NamedEntity.java","lineNumber":37,"sourceCode":"package org.apache.pulsar.common.naming;\n\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\nimport lombok.experimental.UtilityClass;\n\n/**\n */\n@UtilityClass\npublic class NamedEntity {\n\n    // allowed characters for property, namespace, cluster and topic names are\n    // alphanumeric (a-zA-Z_0-9) and these special chars -=:.\n    // % is allowed as part of valid URL encoding\n    public static final Pattern NAMED_ENTITY_PATTERN = Pattern.compile(\"^[-=:.\\\\w]*$\");\n\n    public static void checkName(String name) throws IllegalArgumentException {\n        if (!isAllowed(name)) {\n            throw new IllegalArgumentException(\"Invalid named entity: \" + name);\n        }\n    }\n\n    public static boolean isAllowed(String name) {\n        Matcher m = NAMED_ENTITY_PATTERN.matcher(name);\n        return m.matches();\n    }\n}","sourceCodeStart":19,"sourceCodeEnd":45,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-common/src/main/java/org/apache/pulsar/common/naming/NamedEntity.java#L19-L45","documentation":"NamedEntity.checkName validates that an entity name (tenant, namespace, topic, cluster, etc.) matches ^[-=:\\.\\w]*$ — only alphanumerics, underscore, and -=:. (plus URL-encoded %). Names with any other character throw IllegalArgumentException(\"Invalid named entity: <name>\").","triggerScenarios":"Calling checkName (or APIs that call it, like tenant/namespace/topic creation) with a name containing spaces, slashes outside allowed positions, unicode, '@', '#', or other special characters.","commonSituations":"User-supplied names passed through unvalidated (e.g. from HTTP requests or labels), names containing '/' when the caller already split the path, email addresses or paths used as tenant names.","solutions":["Sanitize the name to allowed characters (a-zA-Z0-9_-=:.) before passing it","URL-encode disallowed characters if the name must carry special data","Use NamedEntity.isAllowed(name) to validate before calling APIs that throw"],"exampleFix":"// before\nString tenant = \"my tenant/ops\"; // invalid: space and slash\nNamespaceName ns = NamespaceName.get(tenant + \"/app\");\n// after\nString tenant = \"my-tenant-ops\"; // sanitized\nNamespaceName ns = NamespaceName.get(tenant + \"/app\");","handlingStrategy":"validation","validationCode":"private static final Pattern SAFE = Pattern.compile(\"^[-=:.\\\\w]*$\");\nif (name == null || !SAFE.matcher(name).matches()) {\n    throw new IllegalArgumentException(\"Name contains disallowed characters: \" + name);\n}","typeGuard":"boolean isValidEntityName(String name) {\n    return name != null && NamedEntity.isAllowed(name);\n}","tryCatchPattern":"try {\n    NamedEntity.checkName(name);\n} catch (IllegalArgumentException e) {\n    throw new IllegalArgumentException(\"Rejecting invalid entity name (allowed: a-zA-Z0-9_-=:.): \" + name, e);\n}","preventionTips":["Sanitize or URL-encode user-supplied names at the API boundary","Reject spaces, slashes, and unicode in tenant/namespace/topic names early in your own validation","Add a form/UI-level regex matching NAMED_ENTITY_PATTERN before submitting names"],"tags":["validation","naming","pulsar-common","regex"],"backgroundTag":"invalid-entity-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"}