Skip to content

Commit 377e4f3

Browse files
committed
Merge pull request #10658 from dreis2211:assert-state-supplier
* pr/10658: Polish "Use Assert.state() with Supplier where possible" Use Assert.state() with Supplier where possible
2 parents 3e18213 + 2eba1c5 commit 377e4f3

File tree

21 files changed

+30
-28
lines changed

21 files changed

+30
-28
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/EndpointRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private String getPathId(Object source) {
163163
private String getPathId(Class<?> source) {
164164
Endpoint annotation = AnnotationUtils.findAnnotation(source, Endpoint.class);
165165
Assert.state(annotation != null,
166-
"Class " + source + " is not annotated with @Endpoint");
166+
() -> "Class " + source + " is not annotated with @Endpoint");
167167
return annotation.id();
168168
}
169169

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/annotation/AnnotationEndpointDiscoverer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private Map<Class<?>, EndpointExtensionInfo<T>> discoverExtensions(
140140
AnnotationAttributes endpointAttributes = AnnotatedElementUtils
141141
.getMergedAnnotationAttributes(endpointType, Endpoint.class);
142142
Assert.state(isExposedOver(endpointAttributes, exposure),
143-
"Invalid extension " + beanType.getName() + "': endpoint '"
143+
() -> "Invalid extension " + beanType.getName() + "': endpoint '"
144144
+ endpointType.getName()
145145
+ "' does not support such extension");
146146
EndpointInfo<T> info = getEndpointInfo(endpoints, beanType, endpointType);
@@ -163,7 +163,7 @@ private Map<Class<?>, EndpointExtensionInfo<T>> discoverExtensions(
163163
private EndpointInfo<T> getEndpointInfo(Map<Class<?>, EndpointInfo<T>> endpoints,
164164
Class<?> beanType, Class<?> endpointClass) {
165165
EndpointInfo<T> endpoint = endpoints.get(endpointClass);
166-
Assert.state(endpoint != null, "Invalid extension '" + beanType.getName()
166+
Assert.state(endpoint != null, () -> "Invalid extension '" + beanType.getName()
167167
+ "': no endpoint found with type '" + endpointClass.getName() + "'");
168168
return endpoint;
169169
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheConfigurations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private CacheConfigurations() {
5252

5353
public static String getConfigurationClass(CacheType cacheType) {
5454
Class<?> configurationClass = MAPPINGS.get(cacheType);
55-
Assert.state(configurationClass != null, "Unknown cache type " + cacheType);
55+
Assert.state(configurationClass != null, () -> "Unknown cache type " + cacheType);
5656
return configurationClass.getName();
5757
}
5858

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public void checkLocationExists() {
124124
"Migration script locations not configured");
125125
boolean exists = hasAtLeastOneLocation();
126126
Assert.state(exists,
127-
"Cannot find migrations location in: " + this.properties
127+
() -> "Cannot find migrations location in: " + this.properties
128128
.getLocations()
129129
+ " (please add migrations or check your Flyway configuration)");
130130
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public void setDriverClassName(String driverClassName) {
232232
public String determineDriverClassName() {
233233
if (StringUtils.hasText(this.driverClassName)) {
234234
Assert.state(driverClassIsLoadable(),
235-
"Cannot load driver class: " + this.driverClassName);
235+
() -> "Cannot load driver class: " + this.driverClassName);
236236
return this.driverClassName;
237237
}
238238
String driverClassName = null;

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void checkChangelogExists() {
103103
Resource resource = this.resourceLoader
104104
.getResource(this.properties.getChangeLog());
105105
Assert.state(resource.exists(),
106-
"Cannot find changelog location: " + resource
106+
() -> "Cannot find changelog location: " + resource
107107
+ " (please add changelog or check your Liquibase "
108108
+ "configuration)");
109109
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionStoreMappings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private SessionStoreMappings() {
4848
public static String getConfigurationClass(StoreType sessionStoreType) {
4949
Class<?> configurationClass = MAPPINGS.get(sessionStoreType);
5050
Assert.state(configurationClass != null,
51-
"Unknown session store type " + sessionStoreType);
51+
() -> "Unknown session store type " + sessionStoreType);
5252
return configurationClass.getName();
5353
}
5454

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/SocialWebAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public String getUserId() {
178178
SecurityContext context = SecurityContextHolder.getContext();
179179
Authentication authentication = context.getAuthentication();
180180
Assert.state(authentication != null,
181-
"Unable to get a " + "ConnectionRepository: no user signed in");
181+
"Unable to get a ConnectionRepository: no user signed in");
182182
return authentication.getName();
183183
}
184184

spring-boot-project/spring-boot-cli/src/it/java/org/springframework/boot/cli/infrastructure/CommandLineInvoker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private File findLaunchScript() throws IOException {
9393
}
9494
File bin = new File(unpacked.listFiles()[0], "bin");
9595
File launchScript = new File(bin, isWindows() ? "spring.bat" : "spring");
96-
Assert.state(launchScript.exists() && launchScript.isFile(),
96+
Assert.state(launchScript.exists() && launchScript.isFile(), () ->
9797
"Could not find CLI launch script " + launchScript.getAbsolutePath());
9898
return launchScript;
9999
}

spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/filewatch/ChangedFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public String getRelativeName() {
7676
File file = this.file.getAbsoluteFile();
7777
String folderName = StringUtils.cleanPath(folder.getPath());
7878
String fileName = StringUtils.cleanPath(file.getPath());
79-
Assert.state(fileName.startsWith(folderName), "The file " + fileName
79+
Assert.state(fileName.startsWith(folderName), () -> "The file " + fileName
8080
+ " is not contained in the source folder " + folderName);
8181
return fileName.substring(folderName.length() + 1);
8282
}

0 commit comments

Comments
 (0)