{"record":{"id":"c7266ef635194dc3","repo":"apache/pulsar","slug":"maxproducerspertopic-must-be-0-or-more","errorCode":null,"errorMessage":"maxProducersPerTopic must be 0 or more","messagePattern":"maxProducersPerTopic 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":2456,"sourceCode":"                }\n            });\n    }\n\n    protected void internalSetDeduplicationSnapshotInterval(Integer interval) {\n        validateNamespacePolicyOperation(namespaceName, PolicyName.DEDUPLICATION_SNAPSHOT, PolicyOperation.WRITE);\n        if (interval != null && interval < 0) {\n            throw new RestException(Status.PRECONDITION_FAILED, \"interval must be greater than or equal to 0\");\n        }\n        internalSetPolicies(\"deduplicationSnapshotIntervalSeconds\", interval);\n    }\n\n    protected void internalSetMaxProducersPerTopic(Integer maxProducersPerTopic) {\n        validateNamespacePolicyOperation(namespaceName, PolicyName.MAX_PRODUCERS, PolicyOperation.WRITE);\n        validatePoliciesReadOnlyAccess();\n\n        try {\n            if (maxProducersPerTopic != null && maxProducersPerTopic < 0) {\n                throw new RestException(Status.PRECONDITION_FAILED,\n                        \"maxProducersPerTopic must be 0 or more\");\n            }\n            updatePolicies(namespaceName, policies -> {\n                policies.max_producers_per_topic = maxProducersPerTopic;\n                return policies;\n            });\n            log.info()\n                    .attr(\"namespace\", namespaceName)\n                    .attr(\"maxProducersPerTopic\", maxProducersPerTopic)\n                    .log(\"Successfully updated maxProducersPerTopic configuration\");\n        } catch (RestException pfe) {\n            throw pfe;\n        } catch (Exception e) {\n            log.error()\n                    .attr(\"namespace\", namespaceName)\n                    .exception(e)\n                    .log(\"Failed to update maxProducersPerTopic configuration for namespace\");\n            throw new RestException(e);","sourceCodeStart":2438,"sourceCodeEnd":2474,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java#L2438-L2474","documentation":"Thrown by internalSetMaxProducersPerTopic when the provided value is negative. The max-producers-per-topic limit is a count and must be null (unset) or >= 0. The broker rejects the update with HTTP 412 PRECONDITION_FAILED before touching the policies.","triggerScenarios":"POST /namespaces/{ns}/maxProducersPerTopic with a negative integer; passing -1 intending 'unlimited' when the correct sentinel is null or 0; variable interpolation bugs in config producing negative numbers.","commonSituations":"Using -1 as 'no limit' (Pulsar expects null/omit); copying limits from another system with different sentinel conventions; CLI tools that don't validate input.","solutions":["Pass 0 or a positive integer (0 means no producers allowed; null/omit means no limit)","Use null to unset the limit instead of -1","Add client-side validation (value == null || value >= 0) before the API call"],"exampleFix":"// before\nadmin.namespaces().setMaxProducersPerTopic(\"my-tenant/my-ns\", -1); // 412\n// after\nadmin.namespaces().setMaxProducersPerTopic(\"my-tenant/my-ns\", null);  // unset / unlimited\nadmin.namespaces().setMaxProducersPerTopic(\"my-tenant/my-ns\", 100);   // explicit limit","handlingStrategy":"validation","validationCode":"if (maxProducersPerTopic != null && maxProducersPerTopic < 0) {\n    throw new IllegalArgumentException(\"maxProducersPerTopic must be >= 0 or null\");\n}","typeGuard":"boolean isValidCount(Integer v) { return v == null || v >= 0; }","tryCatchPattern":"try {\n    admin.namespaces().setMaxProducersPerTopic(ns, maxProducersPerTopic);\n} catch (PulsarAdminException.PreconditionFailedException e) {\n    log.error(\"Negative maxProducersPerTopic rejected: use null for unlimited\");\n    throw e;\n}","preventionTips":["Use null (not -1) to express 'no limit'","Sanitize config values that may default to negative numbers","Centralize policy-value validation in shared tooling"],"tags":["http-412","producers","validation","admin-api"],"backgroundTag":"invalid-policy-value","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"}