As it is often (always?) the case, simpler is better. By just wrapping the check and the exception throwing instructions into a method, one can readily use programming by contract concepts. While no such wrappers are available out-of-the-box in Java, valid4j and Kotlin offer them.