{"record":{"id":"e4c9e69c95d2e097","repo":"json-path/JsonPath","slug":"criteria-build-exception-complete-on-criteria-bef","errorCode":null,"errorMessage":"Criteria build exception. Complete on criteria before defining next.","messagePattern":"Criteria build exception\\. Complete on criteria before defining next\\.","errorType":"exception","errorClass":"JsonPathException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/Criteria.java","lineNumber":509,"sourceCode":"    public static Criteria create(String left, String operator, String right) {\n        Criteria criteria = new Criteria(ValueNode.toValueNode(left));\n        criteria.criteriaType = RelationalOperator.fromString(operator);\n        criteria.right = ValueNode.toValueNode(right);\n        return criteria;\n    }\n\n\n    private static String prefixPath(String key){\n        if (!key.startsWith(\"$\") && !key.startsWith(\"@\")) {\n            key = \"@.\" + key;\n        }\n        return key;\n    }\n\n    private void checkComplete(){\n        boolean complete = (left != null && criteriaType != null && right != null);\n        if(!complete){\n            throw new JsonPathException(\"Criteria build exception. Complete on criteria before defining next.\");\n        }\n    }\n\n}\n","sourceCodeStart":491,"sourceCodeEnd":514,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/Criteria.java#L491-L514","documentation":"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.","triggerScenarios":"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).","commonSituations":"Hand-written filter chains missing a comparison operator, or refactored code where an .eq(...) call was deleted leaving an incomplete criteria before .and(...).","solutions":["Complete the current criterion with an operator+value call (is, eq, ne, gt, ...) before calling and().","Reorder so each Criteria.where(path).op(value) segment is fully formed.","Inspect the chain: exactly one operator+value per path segment."],"exampleFix":"// before\nFilter.filter(Criteria.where(\"$.a\").and(\"$.b\").is(1));\n// after\nFilter.filter(Criteria.where(\"$.a\").is(0).and(\"$.b\").is(1));","handlingStrategy":"validation","validationCode":"// ensure each segment ends with a value-binding call before chaining 'and'\n// e.g. where(\"$.a\").is(x).and(\"$.b\").is(y) — never where(\"$.a\").and(...)","typeGuard":null,"tryCatchPattern":"try {\n    Filter f = Filter.filter(criteria);\n} catch (JsonPathException e) {\n    throw new IllegalStateException(\"Incomplete criteria chain: \" + e.getMessage(), e);\n}","preventionTips":["End every Criteria.where(...) segment with an operator call (.is/.eq/...).","Build chains incrementally and compile early to catch state errors.","Avoid string-manipulating criteria chains in generated code."],"tags":["jsonpath","filter","builder","invalid-state"],"backgroundTag":"invalid-state-transition","analyzedSha":"62a4c9f0f65ba3f625aa0867d64c528ba72d09ec","analyzedAt":"2026-09-11T11:36:00.448Z","contentChangedAt":"2026-09-11T11:36:00.448Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}