{"record":{"id":"67b9701379f7df30","repo":"apache/pulsar","slug":"field-name-must-be-a-positive-number","errorCode":null,"errorMessage":"Field '${name}' must be a Positive Number","messagePattern":"Field '(.+?)' must be a Positive Number","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-config-validation/src/main/java/org/apache/pulsar/config/validation/ValidatorImpls.java","lineNumber":62,"sourceCode":"            this.includeZero = (boolean) params.get(ConfigValidationAnnotations.ValidatorParams.INCLUDE_ZERO);\n        }\n\n        public static void validateField(String name, boolean includeZero, Object o) {\n            if (o == null) {\n                return;\n            }\n            if (o instanceof Number) {\n                if (includeZero) {\n                    if (((Number) o).doubleValue() >= 0.0) {\n                        return;\n                    }\n                } else {\n                    if (((Number) o).doubleValue() > 0.0) {\n                        return;\n                    }\n                }\n            }\n            throw new IllegalArgumentException(String.format(\"Field '%s' must be a Positive Number\", name));\n        }\n\n        @Override\n        public void validateField(String name, Object o) {\n            validateField(name, this.includeZero, o);\n        }\n    }\n\n    /**\n     * Validates if an object is not null.\n     */\n\n    public static class NotNullValidator extends Validator {\n\n        @Override\n        public void validateField(String name, Object o) {\n            if (o == null) {\n                throw new IllegalArgumentException(String.format(\"Field '%s' cannot be null!\", name));","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-config-validation/src/main/java/org/apache/pulsar/config/validation/ValidatorImpls.java#L44-L80","documentation":"ValidatorImpls.PositiveNumberValidator.validateField throws IllegalArgumentException when a value is either not a Number at all or is a Number with doubleValue() <= 0 (or < 0 when includeZero=true). Note it silently accepts null (returns early), so this error is about wrong type or non-positive values.","triggerScenarios":"A config field annotated with @PositiveNumberValidator (or validated via PositiveNumberValidator.validateField) given a negative number, zero without includeZero=true, or a non-numeric value (e.g. a String that never got converted) during ConfigValidation.validateConfig.","commonSituations":"Setting a timeout/port/interval to 0 or a negative number in broker.conf; values like '-1' intended as 'unlimited' where the validator demands > 0; YAML unquoted strings arriving as non-Number objects.","solutions":["Set the field to a number strictly greater than 0 (or >= 0 if the validator was created with INCLUDE_ZERO)","If 0 is a legitimate value, use the INCLUDE_ZERO validator param for that field","Remove units/symbols from the value ('5s' -> numeric field expecting milliseconds, use 5000)","If null should be rejected too, add a NotNullValidator alongside this one, since PositiveNumberValidator passes null through"],"exampleFix":"# before\nbrokerClientOperationTimeoutSeconds: -1\n# after\nbrokerClientOperationTimeoutSeconds: 30","handlingStrategy":"validation","validationCode":"// before validateConfig\nObject v = conf.get(\"brokerClientOperationTimeoutSeconds\");\nif (v != null && (!(v instanceof Number) || ((Number) v).doubleValue() <= 0))\n    throw new IllegalStateException(v + \" is not a positive number\");","typeGuard":"static boolean isPositive(Number n) { return n != null && n.doubleValue() > 0.0; }","tryCatchPattern":"try {\n    ConfigValidation.validateConfig(conf);\n} catch (IllegalArgumentException e) {\n    throw new IllegalStateException(\"Positive-number config violation: \" + e.getMessage(), e);\n}","preventionTips":["Never use -1 or 0 as 'unlimited' for fields annotated with PositiveNumberValidator; check the field's annotation (INCLUDE_ZERO) for whether 0 is allowed","Strip units from values ('30s' -> 30) and use the field's documented unit","Remember null passes PositiveNumberValidator; pair with NotNullValidator for required fields"],"tags":["config-validation","positive-number","illegal-argument"],"backgroundTag":"config-value-out-of-range","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"}