Added check for invalid duration (#1209)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
Christoph Weitkamp 2019-11-13 18:35:42 +01:00 committed by Kai Kreuzer
parent 8c4fb060ed
commit d77d8b763e

View File

@ -43,8 +43,12 @@ public class ExpiringCache<V> {
*
* @param expiry the duration for how long the value stays valid
* @param action the action to retrieve/calculate the value
* @throws IllegalArgumentException For an expire value <=0.
*/
public ExpiringCache(Duration expiry, Supplier<@Nullable V> action) {
if (expiry.isNegative() || expiry.isZero()) {
throw new IllegalArgumentException("Cache expire time must be greater than 0");
}
this.expiry = expiry.toNanos();
this.action = action;
}