{"record":{"id":"26e5a53f57025943","repo":"jhy/jsoup","slug":"the-s-parameter-must-not-be-empty","errorCode":null,"errorMessage":"The '%s' parameter must not be empty.","messagePattern":"The '(.+?)' parameter must not be empty\\.","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/jsoup/helper/Validate.java","lineNumber":156,"sourceCode":"    /**\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\n     */\n    public static void notEmpty(@Nullable String string, String msg) {\n        if (string == null || string.length() == 0)\n            throw new ValidationException(msg);\n    }\n\n    /**\n     * Blow up if we reach an unexpected state.\n     * @param msg message to think about\n     * @throws IllegalStateException if we reach this state\n     */","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/jhy/jsoup/blob/9851ac5d9c576c6888910b5a51a2362bbc978959/src/main/java/org/jsoup/helper/Validate.java#L138-L174","documentation":"jsoup's Validate.notEmptyParam is a precondition check that throws a ValidationException when a caller passes null or an empty ('' length 0) string as a named method parameter. The message names the offending parameter so the caller can locate the bad argument. It is jsoup's way of failing fast on empty required String inputs instead of propagating confusing downstream behavior.","triggerScenarios":"Any public jsoup API whose implementation calls Validate.notEmptyParam(string, param) and receives null or \"\" — e.g. passing an empty string as an attribute name, element tag, selector, or other required string parameter.","commonSituations":"Building a document from config or user input where a field is empty; variables initialized to \"\" as a default and then passed to jsoup; reading values from properties/JSON where a key exists but maps to empty; refactors that drop null checks without noticing empty strings also fail.","solutions":["Check the named parameter in the message at the call site and supply a non-null, non-empty value.","Guard your own input: if(empty(s)) throw before calling the jsoup API.","If empty is legitimate in your domain, substitute a sensible default before calling.","If you believe empty should be allowed, file/inspect jsoup issue — this check is a library precondition, not a transient failure."],"exampleFix":"// before\nDocument doc = Jsoup.parse(html, \"\"); // if baseUri empty\n// after\nif (baseUri == null || baseUri.isEmpty()) baseUri = \"about:blank\";\nDocument doc = Jsoup.parse(html, baseUri);","handlingStrategy":"validation","validationCode":"if (param == null || param.isEmpty()) throw new IllegalArgumentException(\"'param' must not be empty before calling jsoup\");","typeGuard":"boolean isPresent(String s) { return s != null && !s.isEmpty(); }","tryCatchPattern":"try { jsoupCall(value); } catch (org.jsoup.helper.ValidationException e) { log.error(\"Missing required string parameter: {}\", e.getMessage()); }","preventionTips":["Never pass \"\" as a default for required string parameters; use null + explicit check or Optional.","Trim user/config input and reject blank values before calling jsoup.","Centralize a requireNonEmpty(String, String) helper in your codebase."],"tags":["validation","null-check","empty-string","parameter-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"}