{"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/a50c7d2a1d57234ac4adf70dbd88ac90db6436e4/src/main/java/tools/jackson/databind/ObjectReader.java#L725-L761","documentation":"ObjectReader.problemCollectingReader(int maxProblems) builds a 'problem collecting' reader that gathers up to maxProblems deserialization issues instead of failing fast, and requires maxProblems to be strictly positive. Passing zero or a negative number throws IllegalArgumentException because a collector that holds zero problems is meaningless and a negative size is an internal configuration error. This API was added in 3.1 alongside the CollectingProblemHandler.","triggerScenarios":"Calling reader.problemCollectingReader(0) or problemCollectingReader(-1); computing maxProblems from a config value that can be unset (defaulting to 0); passing a limit derived from a list size that is empty; off-by-one when translating a 'max errors to tolerate' UI setting into the cap.","commonSituations":"A configurable 'tolerance' setting plumbed straight from a properties file where the property is missing and parses to 0; UI 'stop after N errors' defaulting to 0 meaning 'unlimited' in the app but interpreted literally here; porting code from a different library whose zero/negative had a special meaning.","solutions":["Guard the call site: ensure maxProblems >= 1, using Math.max(1, configured) if you want a sensible floor.","Use the no-arg problemCollectingReader() variant if you just want the default cap.","If '0' means 'unlimited' in your config, map it to a large positive int (or use the defaulting overload) before calling.","Add a precondition check at the configuration boundary so a bad value fails there with a clearer message."],"exampleFix":"// before\nint cap = config.getInt(\"max.errors\", 0); // 0 when unset\nObjectReader r = reader.problemCollectingReader(cap); // throws\n// after\nint cap = Math.max(1, config.getInt(\"max.errors\", 10));\nObjectReader r = reader.problemCollectingReader(cap);","handlingStrategy":"validation","validationCode":"int cap = configuredMax;\nif (cap <= 0) throw new IllegalArgumentException(\"maxProblems must be > 0, got \" + cap);\nObjectReader r = reader.problemCollectingReader(cap);","typeGuard":"// no type guard; primitive int validated by range check","tryCatchPattern":"try {\n    return reader.problemCollectingReader(n);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().equals(\"maxProblems must be positive\")) {\n        return reader.problemCollectingReader(); // fall back to default cap\n    }\n    throw e;\n}","preventionTips":["Floor configured values: Math.max(1, configured).","Use the no-arg problemCollectingReader() when you don't need a custom cap.","Treat 0 as 'use default' in your config layer, not as 'pass 0 through'."],"tags":["object-reader","validation","configuration","problem-handler"],"analyzedSha":"a50c7d2a1d57234ac4adf70dbd88ac90db6436e4","analyzedAt":"2026-08-06T20:31:51.404Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}