{"record":{"id":"4d4388547634e8b2","repo":"jhy/jsoup","slug":"string-must-not-be-empty","errorCode":null,"errorMessage":"String must not be empty","messagePattern":"String must not be empty","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/jsoup/helper/Validate.java","lineNumber":145,"sourceCode":"     * Validates that the array contains no null elements\n     * @param objects the array to test\n     * @param msg message to include in the Exception if validation fails\n     * @throws ValidationException if the array contains a null element\n     */\n    public static void noNullElements(Object[] objects, String msg) {\n        for (Object obj : objects)\n            if (obj == null)\n                throw new ValidationException(msg);\n    }\n\n    /**\n     * Validates that the string is not null and is not empty\n     * @param string the string to test\n     * @throws ValidationException if the string is null or empty\n     */\n    public static void notEmpty(@Nullable String string) {\n        if (string == null || string.length() == 0)\n            throw new ValidationException(\"String must not be empty\");\n    }\n\n    /**\n     Validates that the string parameter is not null and is not empty\n     * @param string the string to test\n     * @param param the name of the parameter, for presentation in the validation exception.\n     * @throws ValidationException if the string is null or empty\n     */\n    public static void notEmptyParam(@Nullable final String string, final String param) {\n        if (string == null || string.length() == 0)\n            throw new ValidationException(String.format(\"The '%s' parameter must not be empty.\", param));\n    }\n\n    /**\n     * Validates that the string is not null and is not empty\n     * @param string the string to test\n     * @param msg message to include in the Exception if validation fails\n     * @throws ValidationException if the string is null or empty","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/jhy/jsoup/blob/9851ac5d9c576c6888910b5a51a2362bbc978959/src/main/java/org/jsoup/helper/Validate.java#L127-L163","documentation":"Validate.notEmpty(string) asserts that a string is both non-null and has length greater than zero, throwing ValidationException(\"String must not be empty\") otherwise. jsoup uses it wherever an empty string would be meaningless or dangerous (e.g. tag names, selectors, keys).","triggerScenarios":"Calling a jsoup API guarded by notEmpty with \"\" or null — e.g. an empty selector string, empty tag name, empty attribute key, or a string built by concatenation/trimming that ended up empty.","commonSituations":"User-supplied search terms or selectors that were blank after trimming; config values read as empty strings from properties/env defaults; split() results containing empty tokens.","solutions":["Trim and check for emptiness before the call; reject blank input with a clear user-facing message","Provide a sensible default for optional string inputs instead of an empty string","Use notEmpty(string, msg) in your own code so failures name the offending field"],"exampleFix":"// before\nString selector = input.trim(); // \"\"\ndoc.select(selector);\n// after\nString selector = input.trim();\nif (!selector.isEmpty()) { doc.select(selector); }\nelse { throw new IllegalArgumentException(\"selector must not be blank\"); }","handlingStrategy":"validation","validationCode":"String s = raw == null ? \"\" : raw.trim();\nif (s.isEmpty()) {\n    throw new IllegalArgumentException(\"selector must not be blank\");\n}","typeGuard":"boolean isBlank(String s) { return s == null || s.trim().isEmpty(); }","tryCatchPattern":"try {\n    doc.select(userSelector);\n} catch (ValidationException e) {\n    if (e.getMessage().equals(\"String must not be empty\")) {\n        promptUserForNonBlankInput();\n    } else { throw e; }\n}","preventionTips":["Trim user input and reject blank strings at your UI/CLI boundary","Guard split()/substring() results against empty tokens","Use notEmpty(s, msg) so failures name the offending field","Provide defaults for optional string config instead of empty strings"],"tags":["empty-string","validation"],"backgroundTag":"empty-required-field","analyzedSha":"9851ac5d9c576c6888910b5a51a2362bbc978959","analyzedAt":"2026-09-08T15:22:04.931Z","contentChangedAt":"2026-09-08T15:22:04.931Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}