Skip to content

Commit 9d73f81

Browse files
committed
Avoid String allocations with Assert.notNull()
1 parent 9e4cddf commit 9d73f81

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/AbstractCacheOperationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -62,7 +62,7 @@ protected <A extends Annotation> CacheMethodDetails<A> create(Class<A> annotatio
6262
Class<?> targetType, String methodName,
6363
Class<?>... parameterTypes) {
6464
Method method = ReflectionUtils.findMethod(targetType, methodName, parameterTypes);
65-
Assert.notNull(method, "requested method '" + methodName + "'does not exist");
65+
Assert.notNull(method, () -> "requested method '" + methodName + "'does not exist");
6666
A cacheAnnotation = method.getAnnotation(annotationType);
6767
return new DefaultCacheMethodDetails<>(method, cacheAnnotation, getCacheName(cacheAnnotation));
6868
}

spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/AnnotationCacheOperationSourceTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -202,7 +202,7 @@ protected <T extends JCacheOperation<?>> T getCacheOperation(
202202

203203
private JCacheOperation<?> getCacheOperation(Class<?> targetType, String methodName, Class<?>... parameterTypes) {
204204
Method method = ReflectionUtils.findMethod(targetType, methodName, parameterTypes);
205-
Assert.notNull(method, "requested method '" + methodName + "'does not exist");
205+
Assert.notNull(method, () -> "requested method '" + methodName + "'does not exist");
206206
return source.getCacheOperation(method, targetType);
207207
}
208208

spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicClassLoader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private URL createResourceUrl(String name, Supplier<byte[]> bytesSupplier) {
155155

156156
private static Method lookupMethod(Class<?> target, String name, Class<?>... parameterTypes) {
157157
Method method = ReflectionUtils.findMethod(target, name, parameterTypes);
158-
Assert.notNull(method, "Expected method '" + name + "' on '" + target.getName());
158+
Assert.notNull(method, () -> "Could not find method '%s' on '%s'".formatted(name, target.getName()));
159159
return method;
160160
}
161161

spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private GenericApplicationContext loadContextForAotProcessing(
205205

206206
Class<?> testClass = mergedConfig.getTestClass();
207207
ContextLoader contextLoader = mergedConfig.getContextLoader();
208-
Assert.notNull(contextLoader, """
208+
Assert.notNull(contextLoader, () -> """
209209
Cannot load an ApplicationContext with a NULL 'contextLoader'. \
210210
Consider annotating test class [%s] with @ContextConfiguration or \
211211
@ContextHierarchy.""".formatted(testClass.getName()));

spring-test/src/main/java/org/springframework/test/context/cache/DefaultCacheAwareContextLoaderDelegate.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ protected ApplicationContext loadContextInternal(MergedContextConfiguration merg
184184
}
185185
else {
186186
String[] locations = mergedContextConfiguration.getLocations();
187-
Assert.notNull(locations, """
187+
Assert.notNull(locations, () -> """
188188
Cannot load an ApplicationContext with a NULL 'locations' array. \
189189
Consider annotating test class [%s] with @ContextConfiguration or \
190190
@ContextHierarchy.""".formatted(mergedContextConfiguration.getTestClass().getName()));
@@ -224,7 +224,7 @@ else if (logger.isDebugEnabled()) {
224224

225225
private ContextLoader getContextLoader(MergedContextConfiguration mergedConfig) {
226226
ContextLoader contextLoader = mergedConfig.getContextLoader();
227-
Assert.notNull(contextLoader, """
227+
Assert.notNull(contextLoader, () -> """
228228
Cannot load an ApplicationContext with a NULL 'contextLoader'. \
229229
Consider annotating test class [%s] with @ContextConfiguration or \
230230
@ContextHierarchy.""".formatted(mergedConfig.getTestClass().getName()));

0 commit comments

Comments
 (0)