From e32287164bb42f46f517864a3762b74dd577bfe2 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Sat, 16 Dec 2017 02:04:59 +0900 Subject: [PATCH] Use Supplier version of Assert.state() Closes gh-11362 --- .../properties/bind/convert/DurationConverter.java | 4 ++-- .../boot/web/servlet/server/SessionStoreDirectory.java | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/convert/DurationConverter.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/convert/DurationConverter.java index 916fd3dede..0fa930710c 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/convert/DurationConverter.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/convert/DurationConverter.java @@ -90,7 +90,7 @@ class DurationConverter implements GenericConverter { return Duration.parse(source); } Matcher matcher = SIMPLE.matcher(source); - Assert.state(matcher.matches(), "'" + source + "' is not a valid duration"); + Assert.state(matcher.matches(), () -> "'" + source + "' is not a valid duration"); long amount = Long.parseLong(matcher.group(1)); ChronoUnit unit = getUnit(matcher.group(2), defaultUnit); return Duration.of(amount, unit); @@ -106,7 +106,7 @@ class DurationConverter implements GenericConverter { return (defaultUnit != null ? defaultUnit.value() : ChronoUnit.MILLIS); } ChronoUnit unit = UNITS.get(value.toLowerCase()); - Assert.state(unit != null, "Unknown unit '" + value + "'"); + Assert.state(unit != null, () -> "Unknown unit '" + value + "'"); return unit; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/SessionStoreDirectory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/SessionStoreDirectory.java index 4af80c19b6..3ff2ee6389 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/SessionStoreDirectory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/SessionStoreDirectory.java @@ -51,9 +51,13 @@ class SessionStoreDirectory { if (!dir.exists() && mkdirs) { dir.mkdirs(); } - Assert.state(!mkdirs || dir.exists(), "Session dir " + dir + " does not exist"); - Assert.state(!dir.isFile(), "Session dir " + dir + " points to a file"); + assertDirectory(mkdirs, dir); return dir; } + private void assertDirectory(boolean mkdirs, File dir) { + Assert.state(!mkdirs || dir.exists(), () -> "Session dir " + dir + " does not exist"); + Assert.state(!dir.isFile(), () -> "Session dir " + dir + " points to a file"); + } + }