{"record":{"id":"78d61cb6de82ab9a","repo":"FasterXML/jackson-databind","slug":"maxproblems-must-be-positive-was-maxproblems","errorCode":null,"errorMessage":"maxProblems must be positive, was: ${maxProblems}","messagePattern":"maxProblems must be positive, was: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/tools/jackson/databind/deser/CollectingProblemHandler.java","lineNumber":110,"sourceCode":"     * Maximum number of problems to collect before stopping.\n     */\n    private final int _maxProblems;\n\n    /**\n     * Constructs a handler with the default maximum problem limit.\n     */\n    public CollectingProblemHandler() {\n        this(DEFAULT_MAX_PROBLEMS);\n    }\n\n    /**\n     * Constructs a handler with a specific maximum problem limit.\n     *\n     * @param maxProblems Maximum number of problems to collect (must be positive)\n     */\n    public CollectingProblemHandler(int maxProblems) {\n        if (maxProblems <= 0) {\n            throw new IllegalArgumentException(\"maxProblems must be positive, was: \" + maxProblems);\n        }\n        _maxProblems = maxProblems;\n    }\n\n    /**\n     * Gets the maximum number of problems this handler will collect.\n     */\n    public int getMaxProblems() {\n        return _maxProblems;\n    }\n\n    /**\n     * Retrieves the problem collection bucket from context attributes.\n     *\n     * @return Problem bucket, or null if not in collecting mode\n     */\n    @SuppressWarnings(\"unchecked\")\n    public static List<CollectedProblem> getBucket(DeserializationContext ctxt) {","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/FasterXML/jackson-databind/blob/87876ca5c0569b4933aec2d30d6225e4b9ba3a43/src/main/java/tools/jackson/databind/deser/CollectingProblemHandler.java#L92-L128","documentation":"Thrown by the CollectingProblemHandler constructor when maxProblems is <= 0. This handler accumulates deserialization problems up to a cap; a non-positive cap is meaningless (it would collect nothing or be unbounded by mistake), so the constructor rejects it.","triggerScenarios":"Constructing new CollectingProblemHandler(0) or new CollectingProblemHandler(negative), or computing the cap from user input/configuration that resolves to zero or a negative number.","commonSituations":"Reading a 'max problems' limit from config where the default is unset (0); passing a size derived from a collection length that is empty; arithmetic that underflows; misinterpreting 0 as 'unlimited'.","solutions":["Pass a strictly positive integer (e.g. CollectingProblemHandler.DEFAULT_MAX_PROBLEMS or a sensible cap like 100).","Validate configuration before construction: if the configured limit is <= 0, fall back to the default.","Treat 0/empty as 'use default' rather than passing it through."],"exampleFix":"// before\nint cap = config.getInt(\"max.problems\", 0);\nhandler = new CollectingProblemHandler(cap);\n\n// after\nint cap = config.getInt(\"max.problems\", CollectingProblemHandler.DEFAULT_MAX_PROBLEMS);\nif (cap <= 0) cap = CollectingProblemHandler.DEFAULT_MAX_PROBLEMS;\nhandler = new CollectingProblemHandler(cap);","handlingStrategy":"validation","validationCode":"int cap = configuredMaxProblems;\nif (cap <= 0) cap = CollectingProblemHandler.DEFAULT_MAX_PROBLEMS;\nhandler = new CollectingProblemHandler(cap);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat 0/negative as 'use default' rather than passing through.","Bound the value to a sensible positive range from configuration.","Unit-test problem-handler construction with edge-case config values."],"tags":["jackson","deserialization","problem-handler","validation","config"],"backgroundTag":null,"analyzedSha":"87876ca5c0569b4933aec2d30d6225e4b9ba3a43","analyzedAt":"2026-08-11T12:55:24.033Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}