{"record":{"id":"49b989352d3c1725","repo":"FasterXML/jackson-databind","slug":"maxproblems-must-be-positive","errorCode":null,"errorMessage":"maxProblems must be positive","messagePattern":"maxProblems must be positive","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/tools/jackson/databind/ObjectReader.java","lineNumber":743,"sourceCode":"     * @since 3.1\n     */\n    public ObjectReader problemCollectingReader() {\n        return problemCollectingReader(CollectingProblemHandler.DEFAULT_MAX_PROBLEMS);\n    }\n\n    /**\n     * Variant of {@link #problemCollectingReader()} that allows overriding maximum\n     * number of problems to collect.\n     *\n     * @param maxProblems Maximum number of problems to collect (must be {@code >} 0)\n     * @return A new ObjectReader configured for problem collection\n     * @throws IllegalArgumentException if maxProblems is {@code <= 0}\n     *\n     * @since 3.1\n     */\n    public ObjectReader problemCollectingReader(int maxProblems) {\n        if (maxProblems <= 0) {\n            throw new IllegalArgumentException(\"maxProblems must be positive\");\n        }\n        return problemCollectingReader(new CollectingProblemHandler(maxProblems));\n    }\n\n    /**\n     * Variant of {@link #problemCollectingReader()} that allows passing custom\n     * {@link CollectingProblemHandler} (usually sub-class).\n     *\n     * @param problemHandler Custom handler instance to use\n     *\n     * @return A new ObjectReader configured for problem collection\n     *\n     * @since 3.1\n     */\n    public ObjectReader problemCollectingReader(CollectingProblemHandler problemHandler)\n    {\n        DeserializationConfig newConfig = _config.withHandler(problemHandler);\n        return _new(this, newConfig, _valueType, _rootDeserializer, _valueToUpdate,","sourceCodeStart":725,"sourceCodeEnd":761,"githubUrl":"https://github.com/FasterXML/jackson-databind/blob/87876ca5c0569b4933aec2d30d6225e4b9ba3a43/src/main/java/tools/jackson/databind/ObjectReader.java#L725-L761","documentation":"Thrown by ObjectReader.problemCollectingReader(int maxProblems) when the maxProblems argument is zero or negative. This method creates a problem-collecting reader that buffers deserialization errors instead of failing immediately; a non-positive limit would mean zero problems can be collected, which defeats the purpose and is rejected.","triggerScenarios":"Calling reader.problemCollectingReader(0) or reader.problemCollectingReader(-1) or passing a computed value that evaluates to <= 0 (e.g., an uninitialized int field defaulting to 0, or a size derived from an empty collection).","commonSituations":"Passing a configurable limit from a properties file or environment variable that defaults to 0 when unset. Deriving maxProblems from a list size that is zero in edge cases. Copy-paste from other builder methods that allow 0.","solutions":["Pass a positive integer: use problemCollectingReader() with no argument for the default limit, or ensure your value is >= 1.","Validate the value before calling: if (maxProblems < 1) maxProblems = CollectingProblemHandler.DEFAULT_MAX_PROBLEMS;","Use reader.problemCollectingReader() (no-arg) if you just want the default problem collection behavior."],"exampleFix":"// before\nint limit = getConfigInt(\"max.problems\", 0); // defaults to 0\nObjectReader r = reader.problemCollectingReader(limit); // throws\n// after\nint limit = Math.max(1, getConfigInt(\"max.problems\", CollectingProblemHandler.DEFAULT_MAX_PROBLEMS));\nObjectReader r = reader.problemCollectingReader(limit);","handlingStrategy":"validation","validationCode":"// Validate before calling\nif (maxProblems <= 0) {\n    throw new IllegalArgumentException(\"maxProblems must be > 0, got: \" + maxProblems);\n}\nreader.problemCollectingReader(maxProblems);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the no-arg problemCollectingReader() for the default limit.","Clamp external config values to at least 1.","Validate configuration at application startup, not at call time."],"tags":["objectreader","validation","problem-collection","argument-validation"],"backgroundTag":null,"analyzedSha":"87876ca5c0569b4933aec2d30d6225e4b9ba3a43","analyzedAt":"2026-08-11T12:55:24.033Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}