{"record":{"id":"70bdaca97a48192b","repo":"karatelabs/karate","slug":"input-must-not-be-null","errorCode":null,"errorMessage":"input must not be null","messagePattern":"input must not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/common/Json.java","lineNumber":106,"sourceCode":"    private final boolean array;\n    private final boolean object;\n    private final String prefix;\n\n    private String prefix(String path) {\n        return path.charAt(0) == '$' ? path : prefix + path;\n    }\n\n    public static Json object() {\n        return new Json(JsonPath.parse(\"{}\"));\n    }\n\n    public static Json array() {\n        return new Json(JsonPath.parse(\"[]\"));\n    }\n\n    public static Json of(Object any) {\n        if (any == null) {\n            throw new IllegalArgumentException(\"input must not be null\");\n        }\n        if (any instanceof String s) {\n            if (s.isBlank()) {\n                throw new IllegalArgumentException(\"input string must not be empty or blank\");\n            }\n            return new Json(JsonPath.parse(parseLenient(s)));\n        } else if (any instanceof List || any instanceof Map) {\n            return new Json(JsonPath.parse(any));\n        } else {\n            String json = JSONValue.toJSONString(any);\n            return new Json(JsonPath.parse(json));\n        }\n    }\n\n    public static Object parseLenient(String json) {\n        if (json == null || json.isBlank()) {\n            throw new RuntimeException(\"invalid json: input is null or blank\");\n        }","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/common/Json.java#L88-L124","documentation":"Json.of() is the entry point that converts an arbitrary object/string into a Json document wrapper; it rejects null outright because there is no meaningful Json document for null input. The throw is an IllegalArgumentException, a caller-contract violation rather than a data-format problem.","triggerScenarios":"Calling Json.of(null) directly, or passing a variable that can be null (e.g. a missing response body or config value) into Json.of().","commonSituations":"Passing response.getBody() results that are null when the HTTP call failed; pipeline values that were never initialized.","solutions":["Check for null before calling Json.of and decide on a default (e.g. empty map/list or Json.array())","Return an empty Json via Json.array() when input is legitimately absent","Fix upstream logic that produced the null value"],"exampleFix":"// before\nJson json = Json.of(body); // NPE risk if body == null\n// after\nJson json = body == null ? Json.array() : Json.of(body);","handlingStrategy":"type-guard","validationCode":"if (input == null) { throw new IllegalStateException(\"Json.of input not initialized\"); }","typeGuard":"// Java: explicit null check before call\nboolean isUsable(Object o) { return o != null; }","tryCatchPattern":"try { Json json = Json.of(input); } catch (IllegalArgumentException e) { if (\"input must not be null\".equals(e.getMessage())) { json = Json.array(); } else { throw e; } }","preventionTips":["Null-check API response bodies before wrapping","Use Optional/Objects.requireNonNull at boundaries","Initialize variables to empty structures instead of null"],"tags":["java","karate","null"],"backgroundTag":"null-argument","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}