{"record":{"id":"80e63c5140c8e511","repo":"jhy/jsoup","slug":"msg-string-format-with-args","errorCode":null,"errorMessage":"msg (String.format with args)","messagePattern":"msg \\(String\\.format with args\\)","errorType":"exception","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/jsoup/helper/Validate.java","lineNumber":206,"sourceCode":"    /**\n     Cause a failure, but return false so it can be used in an assert statement.\n     @param msg message to output.\n     @return false, always\n     @throws IllegalStateException if we reach this state\n     */\n    static boolean assertFail(String msg) {\n        fail(msg);\n        return false;\n    }\n\n    /**\n     Cause a failure.\n     @param msg message to output.\n     @param args the format arguments to the msg\n     @throws IllegalStateException if we reach this state\n     */\n    public static void fail(String msg, Object... args) {\n        throw new ValidationException(String.format(msg, args));\n    }\n}\n","sourceCodeStart":188,"sourceCodeEnd":209,"githubUrl":"https://github.com/jhy/jsoup/blob/9851ac5d9c576c6888910b5a51a2362bbc978959/src/main/java/org/jsoup/helper/Validate.java#L188-L209","documentation":"The varargs overload of Validate.fail throws a ValidationException whose message is String.format(msg, args), enabling parameterized failure messages. It signals a failed precondition/validation in jsoup with formatted detail about the offending values.","triggerScenarios":"A jsoup API calling Validate.fail(format, args...) when validation fails — same class of precondition violations as the single-message fail, but the message includes interpolated values (indices, names, counts) that failed the check.","commonSituations":"Off-by-one or out-of-range indices passed to document accessors; mismatched collection sizes when composing nodes; usage patterns that break documented invariants where the message reports the actual bad value.","solutions":["Parse the formatted message to identify the exact bad value cited.","Correct the argument at the call site to satisfy the precondition.","Add your own bounds/shape checks before calling the jsoup API.","Update jsoup if the violated check reflects an outdated library assumption."],"exampleFix":"// before\ndoc.childNode(i); // i out of range -> formatted fail\n// after\nif (i >= 0 && i < doc.childNodeSize()) doc.childNode(i);","handlingStrategy":"validation","validationCode":"if (index < 0 || index >= node.childNodeSize()) throw new IndexOutOfBoundsException(\"index \" + index + \" out of range\");","typeGuard":null,"tryCatchPattern":"try { /* jsoup operation */ } catch (org.jsoup.helper.ValidationException e) { log.warn(\"jsoup validation failed: {}\", e.getMessage()); }","preventionTips":["Check indices and sizes against accessor methods (childNodeSize()) before calls.","Never assume collection sizes; query them.","Catch ValidationException at boundaries handling user-driven structure."],"tags":["validation","assertion","string-format","precondition"],"backgroundTag":"internal-invariant-violation","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"}