json-path/JsonPath · error · JsonPathException

Criteria build exception. Complete on criteria before defini

Error message

Criteria build exception. Complete on criteria before defining next.

What it means

Criteria is built in stages (path, operator, value). and() calls the private checkComplete() to ensure the current criterion is finished before starting the next; if left path, criteriaType, or right value is missing, JsonPathException is thrown. This is a builder state-machine violation.

Source

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

    public static Criteria create(String left, String operator, String right) {
        Criteria criteria = new Criteria(ValueNode.toValueNode(left));
        criteria.criteriaType = RelationalOperator.fromString(operator);
        criteria.right = ValueNode.toValueNode(right);
        return criteria;
    }


    private static String prefixPath(String key){
        if (!key.startsWith("$") && !key.startsWith("@")) {
            key = "@." + key;
        }
        return key;
    }

    private void checkComplete(){
        boolean complete = (left != null && criteriaType != null && right != null);
        if(!complete){
            throw new JsonPathException("Criteria build exception. Complete on criteria before defining next.");
        }
    }

}

View on GitHub (pinned to 62a4c9f0f6)

Solutions

  1. Complete the current criterion with an operator+value call (is, eq, ne, gt, ...) before calling and().
  2. Reorder so each Criteria.where(path).op(value) segment is fully formed.
  3. Inspect the chain: exactly one operator+value per path segment.

Example fix

// before
Filter.filter(Criteria.where("$.a").and("$.b").is(1));
// after
Filter.filter(Criteria.where("$.a").is(0).and("$.b").is(1));
Defensive patterns

Strategy: validation

Validate before calling

// ensure each segment ends with a value-binding call before chaining 'and'
// e.g. where("$.a").is(x).and("$.b").is(y) — never where("$.a").and(...)

Try / catch

try {
    Filter f = Filter.filter(criteria);
} catch (JsonPathException e) {
    throw new IllegalStateException("Incomplete criteria chain: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: Chaining like Criteria.where("$.a").and("$.b").is(1) — calling and() before the previous criterion got its operator/value (e.g. missing .is(...)/.eq(...) between where and and).

Common situations: Hand-written filter chains missing a comparison operator, or refactored code where an .eq(...) call was deleted leaving an incomplete criteria before .and(...).

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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