Package org.apache.groovy.contracts
Class ThrowsIfSupport
java.lang.Object
org.apache.groovy.contracts.ThrowsIfSupport
Runtime support for
checked @ThrowsIf arm-sets (invoked from
generated code; not intended to be called by user code). The checks report a
broken contract implementation as a ThrowsIfViolation — never
as the arm's declared exception, which is defined behaviour delivered at method
entry.- Since:
- 6.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidThe must-throw check, run when the method body completes normally: no unwoven arm's condition may have held on entry (a woven arm's guard makes this unreachable for that arm by construction).static ThrowableonlyWhen(Throwable thrown, boolean[] held, Class<?>[] types, String[] conditions, boolean exhaustive) The only-when check, run when the method body throws: a throwable matching some arm's exception type must be justified by some matching arm's condition having held on entry.
-
Method Details
-
onlyWhen
public static Throwable onlyWhen(Throwable thrown, boolean[] held, Class<?>[] types, String[] conditions, boolean exhaustive) The only-when check, run when the method body throws: a throwable matching some arm's exception type must be justified by some matching arm's condition having held on entry. A justified (or unmatched, or non-exhaustive) throwable is returned for rethrow — defined behaviour propagates untouched.VirtualMachineErrors (OutOfMemoryError,StackOverflowError, ...) are never judged, whatever the arm types: a VM resource condition is outside contract semantics — no@ThrowsIfclaim, howeverexhaustive, reasons about it — so it always propagates untouched.- Parameters:
thrown- the throwable escaping the method bodyheld- per-arm: whether the arm's condition held on entrytypes- per-arm: the arm's declared exception typeconditions- per-arm: the arm's condition text (for the violation message)exhaustive- whether the whole arm-set claims exhaustiveness (an iff); one-directional arm-sets are never only-when checked- Returns:
thrown, for rethrow, when it is in-contract- Throws:
ThrowsIfViolation- whenthrownmatches an arm's type but no matching arm's condition held
-
mustThrow
The must-throw check, run when the method body completes normally: no unwoven arm's condition may have held on entry (a woven arm's guard makes this unreachable for that arm by construction).- Parameters:
held- per-unwoven-arm: whether the arm's condition held on entryconditions- per-unwoven-arm: the arm's condition text (for the violation message)- Throws:
ThrowsIfViolation- when some condition held and the method nevertheless returned
-