json-path/JsonPath · error · InvalidPathException

Criteria can not be null

Error message

Criteria can not be null

What it means

The deprecated Criteria.parse(String) helper throws InvalidPathException when handed a null criteria string. It requires a non-null string it can split on spaces into path/operator/value parts, so null input is rejected immediately.

Source

Thrown at json-path/src/main/java/com/jayway/jsonpath/Criteria.java:471

     */
    public Criteria matches(Predicate p) {
        this.criteriaType = RelationalOperator.MATCHES;
        this.right = new PredicateNode(p);
        return this;
    }

    /**
     * Parse the provided criteria
     *
     * Deprecated use {@link Filter#parse(String)}
     *
     * @param criteria
     * @return a criteria
     */
    @Deprecated
    public static Criteria parse(String criteria) {
        if(criteria == null){
            throw new InvalidPathException("Criteria can not be null");
        }
        String[] split = criteria.trim().split(" ");
        if(split.length == 3){
            return create(split[0], split[1], split[2]);
        } else if(split.length == 1){
            return create(split[0], "EXISTS", "true");
        } else {
            throw new InvalidPathException("Could not parse criteria");
        }
    }

    /**
     * Creates a new criteria
     * @param left path to evaluate in criteria
     * @param operator operator
     * @param right expected value
     * @return a new Criteria
     */

View on GitHub (pinned to 62a4c9f0f6)

Solutions

  1. Migrate off the deprecated Criteria.parse(String) to Criteria.create(path, operator, value) or Filter.where(...).
  2. Guard the input: throw a clear validation error or default before calling parse.
  3. Fix the configuration/parameter source that yields null.
  4. Trim/validate user-supplied criteria strings before building filters.

Example fix

// before
Criteria c = Criteria.parse(config.get("filter"));
// after
String filter = config.get("filter");
if (filter == null) throw new IllegalArgumentException("filter config is required");
Criteria c = Criteria.parse(filter);
Defensive patterns

Strategy: type-guard

Validate before calling

Objects.requireNonNull(criteria, "criteria must not be null");

Type guard

if (criteria == null) { throw new IllegalArgumentException("criteria required"); }

Try / catch

try {
    Criteria c = Criteria.parse(criteria);
} catch (InvalidPathException e) {
    throw new IllegalArgumentException("Bad criteria: " + criteria, e);
}

Prevention

When it happens

Trigger: Criteria.parse(null) — typically when the criteria string comes from configuration, a request parameter, or user input that was never populated.

Common situations: Legacy code still using the deprecated string-based filter builder where a config key or query parameter is missing, so null flows into parse().

Related errors


AI-assisted analysis of json-path/JsonPath@62a4c9f0f6 (2026-09-11). Data as JSON: /api/errors/d8cd711b41822196. Report an issue: GitHub.