jhy/jsoup · error · ValidationException
Must be true
Error message
Must be true
What it means
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.
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
Example fix
// before
Validate.isTrue(elements.size() == 1); // throws on any other count
// after
if (elements.size() == 1) { process(elements.get(0)); }
else { handleUnexpectedCount(elements.size()); } Defensive patterns
Strategy: validation
Validate before calling
if (!condition) {
// handle the violated precondition yourself before the guarded call
throw new IllegalStateException("Expected condition did not hold");
} Try / catch
try {
guardedOperation();
} catch (ValidationException e) {
if (e.getMessage().equals("Must be true")) {
log.warn("Precondition violated; using fallback path");
fallback();
} else { throw e; }
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Must be false
- msg (String.format with args)
- Pattern syntax error:
- Pattern complexity error
- Pattern syntax error:
AI-assisted analysis of jhy/jsoup@9851ac5d9c (2026-09-08).
Data as JSON: /api/errors/06f281fedd88bc7d.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/org/jsoup/helper/Validate.java:82
@param msg the String format message to include in the validation exception when thrown
@param args the arguments to the msg
@return the object, or throws an exception if it is null
@throws ValidationException if the object is null
*/
public static <T> T expectNotNull(@Nullable T obj, String msg, Object... args) {
if (obj == null)
throw new ValidationException(String.format(msg, args));
else return obj;
}
/**
* Validates that the value is true
* @param val object to test
* @throws ValidationException if the object is not true
*/
public static void isTrue(boolean val) {
if (!val)
throw new ValidationException("Must be true");
}
/**
* Validates that the value is true
* @param val object to test
* @param msg message to include in the Exception if validation fails
* @throws ValidationException if the object is not true
*/
public static void isTrue(boolean val, String msg) {
if (!val)
throw new ValidationException(msg);
}
/**
* Validates that the value is false
* @param val object to test
* @throws ValidationException if the object is not false
*/View on GitHub (pinned to 9851ac5d9c)