{"record":{"id":"29ee9584a292ae6c","repo":"json-path/JsonPath","slug":"string-format-message-values","errorCode":null,"errorMessage":"String.format(message, values)","messagePattern":"String\\.format\\(message, values\\)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/internal/Utils.java","lineNumber":443,"sourceCode":"\n    /**\n     * <p>Validate that the specified argument character sequence is\n     * neither {@code null} nor a length of zero (no characters);\n     * otherwise throwing an exception with the specified message.\n     * <p/>\n     * <pre>Validate.notEmpty(myString, \"The string must not be empty\");</pre>\n     *\n     * @param <T>     the character sequence type\n     * @param chars   the character sequence to check, validated not null by this method\n     * @param message the {@link String#format(String, Object...)} exception message if invalid, not null\n     * @param values  the optional values for the formatted exception message, null array not recommended\n     * @return the validated character sequence (never {@code null} method for chaining)\n     * @throws NullPointerException     if the character sequence is {@code null}\n     * @throws IllegalArgumentException if the character sequence is empty\n     */\n    public static <T extends CharSequence> T notEmpty(T chars, String message, Object... values) {\n        if (chars == null || chars.length() == 0) {\n            throw new IllegalArgumentException(String.format(message, values));\n        }\n        return chars;\n    }\n\n\n    //---------------------------------------------------------\n    //\n    // Converters\n    //\n    //---------------------------------------------------------\n    public static String toString(Object o) {\n        if (null == o) {\n            return null;\n        }\n        return o.toString();\n    }\n\n    private Utils() {","sourceCodeStart":425,"sourceCodeEnd":461,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/Utils.java#L425-L461","documentation":"Utils.notEmpty(chars, message, values...) is an internal precondition guard: it throws IllegalArgumentException (with the formatted message) when the given CharSequence is null or has length 0. It is Jayway JsonPath's way of asserting that required string arguments (paths, keys, etc.) are non-empty before proceeding.","triggerScenarios":"Any internal call site validating a CharSequence argument with Utils.notEmpty(...) where the caller passes null or \"\" — e.g. calling JsonPath.compile(\"\"), Path with an empty path string, put()/renameKey()/add() with an empty key, or an empty criteria value passed into filter builders.","commonSituations":"Paths or keys built dynamically from config/environment variables that resolve to empty strings; splitting a comma-separated path list that yields empty entries; empty JSON pointer fragments passed through APIs.","solutions":["Ensure the argument passed to JsonPath APIs is a non-null, non-empty string before calling.","Check the code producing the path/key (config, env var, split result) and filter out empty values.","Provide a sensible default path/key when the dynamic value is blank."],"exampleFix":"// before\nString path = System.getenv(\"JSON_PATH\"); // may be null/empty\nDocumentContext ctx = JsonPath.parse(json).read(path); // IllegalArgumentException\n// after\nString path = System.getenv(\"JSON_PATH\");\nif (path == null || path.isEmpty()) path = \"$\";\nDocumentContext ctx = JsonPath.parse(json).read(path);","handlingStrategy":"validation","validationCode":"if (path == null || path.isEmpty()) {\n    throw new IllegalArgumentException(\"JsonPath string must be non-null and non-empty\");\n}\nString key = configKey != null ? configKey.trim() : \"\";\nif (key.isEmpty()) { /* substitute default or fail fast */ }","typeGuard":null,"tryCatchPattern":"try {\n    return JsonPath.compile(path);\n} catch (IllegalArgumentException e) {\n    // empty/null path argument rejected by Utils.notEmpty\n    throw new IllegalArgumentException(\"Empty or null path supplied to JsonPath\", e);\n}","preventionTips":["Trim and check dynamic path/key values before passing them to JsonPath APIs.","Filter empty entries when building paths from split/config lists.","Fail fast at config load time if required path fields are blank."],"tags":["json-path","precondition","empty-string","illegal-argument"],"backgroundTag":"empty-required-field","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"}