FasterXML/jackson-databind · error · IllegalArgumentException

maxProblems must be positive

Error message

maxProblems must be positive

What it means

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.

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 a50c7d2a1d)

Solutions

  1. Guard the call site: ensure maxProblems >= 1, using Math.max(1, configured) if you want a sensible floor.
  2. Use the no-arg problemCollectingReader() variant if you just want the default cap.
  3. If '0' means 'unlimited' in your config, map it to a large positive int (or use the defaulting overload) before calling.
  4. Add a precondition check at the configuration boundary so a bad value fails there with a clearer message.

Example fix

// before
int cap = config.getInt("max.errors", 0); // 0 when unset
ObjectReader r = reader.problemCollectingReader(cap); // throws
// after
int cap = Math.max(1, config.getInt("max.errors", 10));
ObjectReader r = reader.problemCollectingReader(cap);
Defensive patterns

Strategy: validation

Validate before calling

int cap = configuredMax;
if (cap <= 0) throw new IllegalArgumentException("maxProblems must be > 0, got " + cap);
ObjectReader r = reader.problemCollectingReader(cap);

Type guard

// no type guard; primitive int validated by range check

Try / catch

try {
    return reader.problemCollectingReader(n);
} catch (IllegalArgumentException e) {
    if (e.getMessage().equals("maxProblems must be positive")) {
        return reader.problemCollectingReader(); // fall back to default cap
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of FasterXML/jackson-databind@a50c7d2a1d (2026-08-06). Data as JSON: /api/errors/49b989352d3c1725. Report an issue: GitHub.