{"record":{"id":"56e6e1df15b71b29","repo":"apache/pulsar","slug":"maxtopicspernamespace-must-be-0-or-more","errorCode":null,"errorMessage":"maxTopicsPerNamespace must be 0 or more","messagePattern":"maxTopicsPerNamespace must be 0 or more","errorType":"validation","errorClass":"RestException","httpStatus":412,"severity":"error","filePath":"pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java","lineNumber":2977,"sourceCode":"            log.error()\n                    .attr(\"namespace\", namespaceName)\n                    .exception(e)\n                    .log(\"Failed to remove offload configuration for namespace\");\n            asyncResponse.resume(new RestException(e));\n        }\n    }\n\n   protected void internalRemoveMaxTopicsPerNamespace() {\n        validateNamespacePolicyOperation(namespaceName, PolicyName.MAX_TOPICS, PolicyOperation.WRITE);\n        internalSetMaxTopicsPerNamespace(null);\n   }\n\n   protected void internalSetMaxTopicsPerNamespace(Integer maxTopicsPerNamespace) {\n        validateNamespacePolicyOperation(namespaceName, PolicyName.MAX_TOPICS, PolicyOperation.WRITE);\n        validatePoliciesReadOnlyAccess();\n\n        if (maxTopicsPerNamespace != null && maxTopicsPerNamespace < 0) {\n            throw new RestException(Status.PRECONDITION_FAILED,\n                    \"maxTopicsPerNamespace must be 0 or more\");\n        }\n        internalSetPolicies(\"max_topics_per_namespace\", maxTopicsPerNamespace);\n   }\n\n   protected void internalSetProperty(String key, String value, AsyncResponse asyncResponse) {\n       validateAdminAccessForTenantAsync(namespaceName.getTenant())\n               .thenCompose(__ -> validatePoliciesReadOnlyAccessAsync())\n               .thenCompose(__ -> updatePoliciesAsync(namespaceName, policies -> {\n                   policies.properties.put(key, value);\n                   return policies;\n               }))\n               .thenAccept(v -> {\n                   log.info()\n                           .attr(\"key\", key)\n                           .attr(\"namespace\", namespaceName)\n                           .log(\"Successfully set property for key on namespace\");\n                   asyncResponse.resume(Response.noContent().build());","sourceCodeStart":2959,"sourceCodeEnd":2995,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java#L2959-L2995","documentation":"Guard in internalSetMaxTopicsPerNamespace: the maxTopicsPerNamespace limit was negative, so the namespace-policy write fails with 412 Precondition Failed; zero means unlimited topics and the value must be zero or a positive integer.","triggerScenarios":"Thrown at pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java:2977 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Send a non-negative topic limit; 0 blocks new topic creation","Use the remove endpoint to clear the limit instead of passing a negative number"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}