FasterXML/jackson-databind · error · IllegalArgumentException
maxProblems must be positive
Error message
maxProblems must be positive
What it means
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.
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.
Example fix
// before
int limit = getConfigInt("max.problems", 0); // defaults to 0
ObjectReader r = reader.problemCollectingReader(limit); // throws
// after
int limit = Math.max(1, getConfigInt("max.problems", CollectingProblemHandler.DEFAULT_MAX_PROBLEMS));
ObjectReader r = reader.problemCollectingReader(limit); Defensive patterns
Strategy: validation
Validate before calling
// Validate before calling
if (maxProblems <= 0) {
throw new IllegalArgumentException("maxProblems must be > 0, got: " + maxProblems);
}
reader.problemCollectingReader(maxProblems); Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- deserialization problems (showing first 5):%n
- argument " " is null
- argument " " is null
- Cannot pass null property name
- Cannot set maxDeserializerCacheSize to a negative value
AI-assisted analysis of FasterXML/jackson-databind@87876ca5c0 (2026-08-11).
Data as JSON: /api/errors/49b989352d3c1725.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/tools/jackson/databind/ObjectReader.java:743
* @since 3.1
*/
public ObjectReader problemCollectingReader() {
return problemCollectingReader(CollectingProblemHandler.DEFAULT_MAX_PROBLEMS);
}
/**
* Variant of {@link #problemCollectingReader()} that allows overriding maximum
* number of problems to collect.
*
* @param maxProblems Maximum number of problems to collect (must be {@code >} 0)
* @return A new ObjectReader configured for problem collection
* @throws IllegalArgumentException if maxProblems is {@code <= 0}
*
* @since 3.1
*/
public ObjectReader problemCollectingReader(int maxProblems) {
if (maxProblems <= 0) {
throw new IllegalArgumentException("maxProblems must be positive");
}
return problemCollectingReader(new CollectingProblemHandler(maxProblems));
}
/**
* Variant of {@link #problemCollectingReader()} that allows passing custom
* {@link CollectingProblemHandler} (usually sub-class).
*
* @param problemHandler Custom handler instance to use
*
* @return A new ObjectReader configured for problem collection
*
* @since 3.1
*/
public ObjectReader problemCollectingReader(CollectingProblemHandler problemHandler)
{
DeserializationConfig newConfig = _config.withHandler(problemHandler);
return _new(this, newConfig, _valueType, _rootDeserializer, _valueToUpdate,View on GitHub (pinned to 87876ca5c0)