Pattern: Missing use of require
Issue: -
Kotlin provides a much more concise way to check preconditions than to manually throw an IllegalArgumentException
.
Example of incorrect code:
if (value == null) throw new IllegalArgumentException("value should not be null")
if (value < 0) throw new IllegalArgumentException("value is $value but should be at least 0")
Example of correct code:
requireNotNull(value) {"value should not be null"}
require(value >= 0) { "value is $value but should be at least 0" }