{"record":{"id":"06f281fedd88bc7d","repo":"jhy/jsoup","slug":"must-be-true","errorCode":null,"errorMessage":"Must be true","messagePattern":"Must be true","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/jsoup/helper/Validate.java","lineNumber":82,"sourceCode":"     @param msg the String format message to include in the validation exception when thrown\n     @param args the arguments to the msg\n     @return the object, or throws an exception if it is null\n     @throws ValidationException if the object is null\n     */\n    public static <T> T expectNotNull(@Nullable T obj, String msg, Object... args) {\n        if (obj == null)\n            throw new ValidationException(String.format(msg, args));\n        else return obj;\n    }\n\n    /**\n     * Validates that the value is true\n     * @param val object to test\n     * @throws ValidationException if the object is not true\n     */\n    public static void isTrue(boolean val) {\n        if (!val)\n            throw new ValidationException(\"Must be true\");\n    }\n\n    /**\n     * Validates that the value is true\n     * @param val object to test\n     * @param msg message to include in the Exception if validation fails\n     * @throws ValidationException if the object is not true\n     */\n    public static void isTrue(boolean val, String msg) {\n        if (!val)\n            throw new ValidationException(msg);\n    }\n\n    /**\n     * Validates that the value is false\n     * @param val object to test\n     * @throws ValidationException if the object is not false\n     */","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/jhy/jsoup/blob/9851ac5d9c576c6888910b5a51a2362bbc978959/src/main/java/org/jsoup/helper/Validate.java#L64-L100","documentation":"Validate.isTrue(val) is a boolean assertion helper: it throws ValidationException(\"Must be true\") when the supplied condition evaluates to false. jsoup uses it to enforce internal preconditions and invariants on inputs.","triggerScenarios":"Any code path (in jsoup or your own helpers built on Validate) where a required precondition is false — e.g. an assumed state of a parsed document, a required flag, or an assumed relationship between parsed values that did not hold.","commonSituations":"Assumptions about HTML structure that a malformed page violates; invariant checks in custom parsers built on jsoup's Validate utility; edge cases in input data that the assertion author did not anticipate.","solutions":["Check the condition yourself before the guarded call and handle the false case gracefully","Loosen or correct the assumption that produced the false condition","Use the msg-carrying variant (isTrue(val, msg)) so failures explain which invariant broke"],"exampleFix":"// before\nValidate.isTrue(elements.size() == 1); // throws on any other count\n// after\nif (elements.size() == 1) { process(elements.get(0)); }\nelse { handleUnexpectedCount(elements.size()); }","handlingStrategy":"validation","validationCode":"if (!condition) {\n    // handle the violated precondition yourself before the guarded call\n    throw new IllegalStateException(\"Expected condition did not hold\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    guardedOperation();\n} catch (ValidationException e) {\n    if (e.getMessage().equals(\"Must be true\")) {\n        log.warn(\"Precondition violated; using fallback path\");\n        fallback();\n    } else { throw e; }\n}","preventionTips":["Don't assume document structure; verify counts/shape before asserting","Prefer the isTrue(val, msg) variant so failures are self-explanatory","Add unit tests for malformed inputs that can falsify your assumptions"],"tags":["assertion","validation","boolean"],"backgroundTag":"invalid-argument-value","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"}