{"record":{"id":"9796ab3014151487","repo":"jhy/jsoup","slug":"msg","errorCode":null,"errorMessage":"msg","messagePattern":"msg","errorType":"exception","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/jsoup/helper/Validate.java","lineNumber":135,"sourceCode":"    /**\n     * Validates that the array contains no null elements\n     * @param objects the array to test\n     * @throws ValidationException if the array contains a null element\n     */\n    public static void noNullElements(Object[] objects) {\n        noNullElements(objects, \"Array must not contain any null objects\");\n    }\n\n    /**\n     * 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     */","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/jhy/jsoup/blob/9851ac5d9c576c6888910b5a51a2362bbc978959/src/main/java/org/jsoup/helper/Validate.java#L117-L153","documentation":"Validate.noNullElements(objects, msg) iterates an array and throws ValidationException with the caller-supplied msg if any element is null. The message is passed in by the caller, so the thrown text ('msg' here) is whatever the guarding code specified.","triggerScenarios":"Passing an array or varargs collection to a jsoup API guarded by noNullElements where at least one slot is null — e.g. a null entry among multiple nodes, attributes, or strings being validated in bulk.","commonSituations":"Building varargs/arrays programmatically where an upstream null slipped in; filtering that produced sparse arrays; forwarding nullable collection elements into APIs that validate whole arrays.","solutions":["Pre-filter the array (e.g. with a stream filter(Objects::nonNull)) before passing it","Validate each element at its source so nulls never enter the array","Include a descriptive msg so failures identify which collection contained the null"],"exampleFix":"// before\nprocess(elements); // elements[1] is null\n// after\nElement[] safe = Arrays.stream(elements).filter(Objects::nonNull).toArray(Element[]::new);\nprocess(safe);","handlingStrategy":"validation","validationCode":"Object[] safe = Arrays.stream(objects).filter(Objects::nonNull).toArray();\nif (safe.length != objects.length) {\n    log.warn(\"Dropped {} null elements\", objects.length - safe.length);\n}","typeGuard":null,"tryCatchPattern":"try {\n    bulkOperation(objects);\n} catch (ValidationException e) {\n    // msg is caller-supplied; identify the collection from it and retry without nulls\n    bulkOperation(Arrays.stream(objects).filter(Objects::nonNull).toArray());\n}","preventionTips":["Filter nulls out of arrays/collections before passing varargs","Validate each element at its source so nulls never accumulate","Give noNullElements a descriptive msg so failures pinpoint the collection"],"tags":["null-check","arrays","validation"],"backgroundTag":"null-argument","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"}