apache/pulsar · error · org.apache.pulsar.broker.admin.RestException
Tenant name or namespace is not valid
Error message
Tenant name or namespace is not valid
What it means
The no-arg validateGlobalNamespaceOwnership() validates this.namespaceName for global namespace ownership, and if the name itself is structurally invalid it throws IllegalArgumentException, translated to HTTP 412 'Tenant name or namespace is not valid'. Other failures (RestException) are rethrown unchanged, so this specifically signals a malformed tenant/namespace name in the resource context.
Source
Thrown at pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java:224
}
protected void validateNamespaceName(String tenant, String namespace) {
try {
this.namespaceName = NamespaceName.get(tenant, namespace);
} catch (IllegalArgumentException e) {
log.warn()
.attr("tenant", tenant)
.attr("namespace", namespace)
.log("Invalid namespace name");
throw new RestException(Status.PRECONDITION_FAILED, "Namespace name is not valid");
}
}
protected void validateGlobalNamespaceOwnership() {
try {
validateGlobalNamespaceOwnership(this.namespaceName);
} catch (IllegalArgumentException e) {
throw new RestException(Status.PRECONDITION_FAILED, "Tenant name or namespace is not valid");
} catch (RestException re) {
throw re;
} catch (Exception e) {
log.warn()
.attr("namespace", namespaceName)
.exceptionMessage(e)
.log("Failed to validate global cluster configuration");
throw new RestException(Status.SERVICE_UNAVAILABLE, "Failed to validate global cluster configuration");
}
}
protected void validateTopicName(String tenant, String namespace, String encodedTopic) {
String topic = Codec.decode(encodedTopic);
try {
this.namespaceName = NamespaceName.get(tenant, namespace);
this.topicName = TopicName.get(domain(), namespaceName, topic);
} catch (IllegalArgumentException e) {
log.warn()
.attr("domain", domain())View on GitHub (pinned to 820761864e)
Solutions
- Validate the tenant name ([a-zA-Z0-9_.-]+) and namespace local name before issuing the request.
- Ensure validateNamespaceName (or proper resource construction) runs before global ownership checks in custom code.
- If using the 'global' tenant for geo-replication, keep the namespace local name valid per Pulsar naming rules.
- Check the request path for malformed or missing tenant/namespace segments.
Example fix
// before
String path = tenant + "/" + ns; // tenant="" -> invalid
validateGlobalNamespaceOwnership();
// after
if (!tenant.matches("[a-zA-Z0-9_.-]+") || !ns.matches("[a-zA-Z0-9_.-]+")) {
throw new IllegalArgumentException("invalid tenant or namespace");
}
validateGlobalNamespaceOwnership(); Defensive patterns
Strategy: validation
Validate before calling
boolean isValidForGlobalOwnership(String tenant, String namespace) {
return tenant != null && tenant.matches("[a-zA-Z0-9_.-]+")
&& namespace != null && namespace.matches("[a-zA-Z0-9_.-]+");
} Type guard
String requireValidTenantNamespace(String tenant, String namespace) {
if (!isValidForGlobalOwnership(tenant, namespace)) {
throw new IllegalArgumentException("invalid tenant or namespace: " + tenant + "/" + namespace);
}
return tenant + "/" + namespace;
} Try / catch
try {
admin.namespaces().createNamespace(ns);
} catch (PulsarAdminException e) {
if (e.getStatusCode() == 412 && e.getMessage().contains("Tenant name or namespace is not valid")) {
log.error("Tenant/namespace '{}' is malformed for global ownership check", ns);
}
} Prevention
- Validate both tenant and namespace segments before global namespace operations
- When using the reserved 'global' tenant, keep the local namespace name valid
- Ensure validateNamespaceName runs before ownership checks in custom resources
When it happens
Trigger: Calling namespace ownership checks on an AdminResource whose namespaceName was never properly validated/constructed — e.g. a global namespace (tenant like 'global') endpoint where the tenant or namespace segment fails NamespaceName validation, or a resource constructed with a malformed path.
Common situations: Using the reserved 'global' tenant with an invalid local namespace part; endpoint paths with malformed tenant segments reaching validateGlobalNamespaceOwnership before validateNamespaceName ran; scripts building namespace URLs from concatenated unvalidated parts.
Related errors
- Namespace name is not valid
- Failed to validate global cluster configuration
- Topic name is not valid
- Cannot create topic in system topic format!
- Need to provide a persistent topic name
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/44b9b2494bba6705.
Report an issue: GitHub.