Skip to content

Commit 5f02323

Browse files
committed
Avoid String allocations with Assert.isTrue()
1 parent 902cdd1 commit 5f02323

File tree

27 files changed

+60
-58
lines changed

27 files changed

+60
-58
lines changed

spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public static Flux<DataBuffer> read(
177177
if (options.length > 0) {
178178
for (OpenOption option : options) {
179179
Assert.isTrue(!(option == StandardOpenOption.APPEND || option == StandardOpenOption.WRITE),
180-
"'" + option + "' not allowed");
180+
() -> "'" + option + "' not allowed");
181181
}
182182
}
183183

spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketRequesterBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 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.
@@ -103,7 +103,7 @@ public RSocketRequester.Builder dataMimeType(@Nullable MimeType mimeType) {
103103

104104
@Override
105105
public RSocketRequester.Builder metadataMimeType(MimeType mimeType) {
106-
Assert.notNull(mimeType, "`metadataMimeType` is required");
106+
Assert.notNull(mimeType, "'metadataMimeType' is required");
107107
this.metadataMimeType = mimeType;
108108
return this;
109109
}
@@ -281,7 +281,7 @@ private Mono<Payload> getSetupPayload(
281281
Mono<DataBuffer> dataMono = Mono.empty();
282282
if (data != null) {
283283
ReactiveAdapter adapter = strategies.reactiveAdapterRegistry().getAdapter(data.getClass());
284-
Assert.isTrue(adapter == null || !adapter.isMultiValue(), "Expected single value: " + data);
284+
Assert.isTrue(adapter == null || !adapter.isMultiValue(), () -> "Expected single value: " + data);
285285
Mono<?> mono = (adapter != null ? Mono.from(adapter.toPublisher(data)) : Mono.just(data));
286286
dataMono = mono.map(value -> {
287287
ResolvableType type = ResolvableType.forClass(value.getClass());

spring-messaging/src/main/java/org/springframework/messaging/rsocket/MetadataEncoder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 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.
@@ -141,7 +141,8 @@ else if (!this.metadataMimeType.equals(mimeType)) {
141141
}
142142
ReactiveAdapter adapter = this.strategies.reactiveAdapterRegistry().getAdapter(metadata.getClass());
143143
if (adapter != null) {
144-
Assert.isTrue(!adapter.isMultiValue(), "Expected single value: " + metadata);
144+
Object originalMetadata = metadata;
145+
Assert.isTrue(!adapter.isMultiValue(), () -> "Expected single value: " + originalMetadata);
145146
metadata = Mono.from(adapter.toPublisher(metadata)).defaultIfEmpty(NO_VALUE);
146147
this.hasAsyncValues = true;
147148
}

spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/RSocketMessageHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 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.
@@ -421,7 +421,7 @@ private MessagingRSocket createResponder(ConnectionSetupPayload setupPayload, RS
421421
String str = setupPayload.dataMimeType();
422422
MimeType dataMimeType = StringUtils.hasText(str) ? MimeTypeUtils.parseMimeType(str) : this.defaultDataMimeType;
423423
Assert.notNull(dataMimeType, "No `dataMimeType` in ConnectionSetupPayload and no default value");
424-
Assert.isTrue(isDataMimeTypeSupported(dataMimeType), "Data MimeType '" + dataMimeType + "' not supported");
424+
Assert.isTrue(isDataMimeTypeSupported(dataMimeType), () -> "Data MimeType '" + dataMimeType + "' not supported");
425425

426426
str = setupPayload.metadataMimeType();
427427
MimeType metaMimeType = StringUtils.hasText(str) ? MimeTypeUtils.parseMimeType(str) : this.defaultMetadataMimeType;

spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessagingTemplate.java

Lines changed: 4 additions & 3 deletions
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.
@@ -138,7 +138,7 @@ public MessageHeaderInitializer getHeaderInitializer() {
138138
*/
139139
@Override
140140
public void send(Message<?> message) {
141-
Assert.notNull(message, "Message is required");
141+
Assert.notNull(message, "Message must not be null");
142142
String destination = SimpMessageHeaderAccessor.getDestination(message.getHeaders());
143143
if (destination != null) {
144144
sendInternal(message);
@@ -224,7 +224,8 @@ public void convertAndSendToUser(String user, String destination, Object payload
224224
throws MessagingException {
225225

226226
Assert.notNull(user, "User must not be null");
227-
Assert.isTrue(!user.contains("%2F"), "Invalid sequence \"%2F\" in user name: " + user);
227+
String username = user;
228+
Assert.isTrue(!user.contains("%2F"), () -> "Invalid sequence \"%2F\" in user name: " + username);
228229
user = StringUtils.replace(user, "/", "%2F");
229230
destination = destination.startsWith("/") ? destination : "/" + destination;
230231
super.convertAndSend(this.destinationPrefix + user + destination, payload, headers, postProcessor);

spring-messaging/src/main/java/org/springframework/messaging/simp/broker/OrderedMessageChannelDecorator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 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.
@@ -148,7 +148,7 @@ public static Runnable getNextMessageTask(Message<?> message) {
148148
public static void configureInterceptor(MessageChannel channel, boolean preserveOrder) {
149149
if (preserveOrder) {
150150
Assert.isInstanceOf(ExecutorSubscribableChannel.class, channel,
151-
"An ExecutorSubscribableChannel is required for `preservePublishOrder`");
151+
"An ExecutorSubscribableChannel is required for 'preservePublishOrder'");
152152
ExecutorSubscribableChannel execChannel = (ExecutorSubscribableChannel) channel;
153153
if (execChannel.getInterceptors().stream().noneMatch(i -> i instanceof CallbackInterceptor)) {
154154
execChannel.addInterceptor(0, new CallbackInterceptor());

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaders.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 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.
@@ -211,7 +211,7 @@ public void setAcceptVersion(@Nullable String... acceptVersions) {
211211
}
212212
Arrays.stream(acceptVersions).forEach(version ->
213213
Assert.isTrue(version != null && (version.equals("1.1") || version.equals("1.2")),
214-
"Invalid version: " + version));
214+
() -> "Invalid version: " + version));
215215
set(ACCEPT_VERSION, StringUtils.arrayToCommaDelimitedString(acceptVersions));
216216
}
217217

spring-messaging/src/main/java/org/springframework/messaging/simp/user/DefaultUserDestinationResolver.java

Lines changed: 2 additions & 2 deletions
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.
@@ -203,7 +203,7 @@ private ParseResult parseSubscriptionMessage(Message<?> message, String sourceDe
203203
}
204204
Principal principal = SimpMessageHeaderAccessor.getUser(headers);
205205
String user = (principal != null ? principal.getName() : null);
206-
Assert.isTrue(user == null || !user.contains("%2F"), "Invalid sequence \"%2F\" in user name: " + user);
206+
Assert.isTrue(user == null || !user.contains("%2F"), () -> "Invalid sequence \"%2F\" in user name: " + user);
207207
Set<String> sessionIds = Collections.singleton(sessionId);
208208
return new ParseResult(sourceDestination, actualDestination, sourceDestination, sessionIds, user);
209209
}

spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ private List<ExchangeFilterFunction> initFilters() {
230230

231231
@Override
232232
public WebTestClient.Builder entityExchangeResultConsumer(Consumer<EntityExchangeResult<?>> entityResultConsumer) {
233-
Assert.notNull(entityResultConsumer, "`entityResultConsumer` is required");
233+
Assert.notNull(entityResultConsumer, "'entityResultConsumer' is required");
234234
this.entityResultConsumer = this.entityResultConsumer.andThen(entityResultConsumer);
235235
return this;
236236
}

spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 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.
@@ -148,8 +148,8 @@ public class MockHttpServletRequestBuilder
148148

149149
private static URI initUri(String url, Object[] vars) {
150150
Assert.notNull(url, "'url' must not be null");
151-
Assert.isTrue(url.startsWith("/") || url.startsWith("http://") || url.startsWith("https://"), "" +
152-
"'url' should start with a path or be a complete HTTP URL: " + url);
151+
Assert.isTrue(url.startsWith("/") || url.startsWith("http://") || url.startsWith("https://"),
152+
() -> "'url' should start with a path or be a complete HTTP URL: " + url);
153153
return UriComponentsBuilder.fromUriString(url).buildAndExpand(vars).encode().toUri();
154154
}
155155

spring-test/src/test/java/org/springframework/test/context/junit4/hybrid/HybridContextLoader.java

Lines changed: 3 additions & 3 deletions
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.
@@ -42,8 +42,8 @@ public class HybridContextLoader extends AbstractGenericContextLoader {
4242

4343
@Override
4444
protected void validateMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
45-
Assert.isTrue(mergedConfig.hasClasses() || mergedConfig.hasLocations(), getClass().getSimpleName()
46-
+ " requires either classes or locations");
45+
Assert.isTrue(mergedConfig.hasResources(),
46+
() -> getClass().getSimpleName() + " requires either classes or locations");
4747
}
4848

4949
@Override

spring-web/src/main/java/org/springframework/http/ContentDisposition.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 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.
@@ -465,7 +465,7 @@ else if (!escaped && ch == '"') {
465465
* @see <a href="https://tools.ietf.org/html/rfc5987">RFC 5987</a>
466466
*/
467467
private static String decodeFilename(String filename, Charset charset) {
468-
Assert.notNull(filename, "'input' String` should not be null");
468+
Assert.notNull(filename, "'input' String should not be null");
469469
Assert.notNull(charset, "'charset' should not be null");
470470
byte[] value = filename.getBytes(charset);
471471
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -531,10 +531,10 @@ private static String escapeQuotationsInFilename(String filename) {
531531
* @see <a href="https://tools.ietf.org/html/rfc5987">RFC 5987</a>
532532
*/
533533
private static String encodeFilename(String input, Charset charset) {
534-
Assert.notNull(input, "`input` is required");
535-
Assert.notNull(charset, "`charset` is required");
534+
Assert.notNull(input, "'input' is required");
535+
Assert.notNull(charset, "'charset' is required");
536536
Assert.isTrue(!StandardCharsets.US_ASCII.equals(charset), "ASCII does not require encoding");
537-
Assert.isTrue(UTF_8.equals(charset) || ISO_8859_1.equals(charset), "Only UTF-8 and ISO-8859-1 supported.");
537+
Assert.isTrue(UTF_8.equals(charset) || ISO_8859_1.equals(charset), "Only UTF-8 and ISO-8859-1 are supported");
538538
byte[] source = input.getBytes(charset);
539539
int len = source.length;
540540
StringBuilder sb = new StringBuilder(len << 1);

spring-web/src/main/java/org/springframework/http/HttpRange.java

Lines changed: 2 additions & 2 deletions
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.
@@ -65,7 +65,7 @@ public ResourceRegion toResourceRegion(Resource resource) {
6565
long contentLength = getLengthFor(resource);
6666
long start = getRangeStart(contentLength);
6767
long end = getRangeEnd(contentLength);
68-
Assert.isTrue(start < contentLength, "'position' exceeds the resource length " + contentLength);
68+
Assert.isTrue(start < contentLength, () -> "'position' exceeds the resource length " + contentLength);
6969
return new ResourceRegion(resource, start, end - start + 1);
7070
}
7171

spring-web/src/main/java/org/springframework/http/codec/json/Jackson2CodecSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ protected Map<String, Object> getHints(ResolvableType resolvableType) {
231231
JsonView annotation = getAnnotation(param, JsonView.class);
232232
if (annotation != null) {
233233
Class<?>[] classes = annotation.value();
234-
Assert.isTrue(classes.length == 1, JSON_VIEW_HINT_ERROR + param);
234+
Assert.isTrue(classes.length == 1, () -> JSON_VIEW_HINT_ERROR + param);
235235
hints = (hints != null ? hints : new HashMap<>(1));
236236
hints.put(JSON_VIEW_HINT, classes[0]);
237237
}

spring-web/src/main/java/org/springframework/http/converter/BufferedImageHttpMessageConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public MediaType getDefaultContentType() {
128128
*/
129129
public void setCacheDir(File cacheDir) {
130130
Assert.notNull(cacheDir, "'cacheDir' must not be null");
131-
Assert.isTrue(cacheDir.isDirectory(), "'cacheDir' is not a directory");
131+
Assert.isTrue(cacheDir.isDirectory(), () -> "'cacheDir' is not a directory: " + cacheDir);
132132
this.cacheDir = cacheDir;
133133
}
134134

spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ protected String serializeForm(MultiValueMap<String, Object> formData, Charset c
436436
StringBuilder builder = new StringBuilder();
437437
formData.forEach((name, values) -> {
438438
if (name == null) {
439-
Assert.isTrue(CollectionUtils.isEmpty(values), "Null name in form data: " + formData);
439+
Assert.isTrue(CollectionUtils.isEmpty(values), () -> "Null name in form data: " + formData);
440440
return;
441441
}
442442
values.forEach(value -> {

spring-web/src/main/java/org/springframework/http/server/reactive/DefaultServerHttpRequestBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 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.
@@ -93,7 +93,7 @@ public ServerHttpRequest.Builder uri(URI uri) {
9393

9494
@Override
9595
public ServerHttpRequest.Builder path(String path) {
96-
Assert.isTrue(path.startsWith("/"), "The path does not have a leading slash.");
96+
Assert.isTrue(path.startsWith("/"), () -> "The path does not have a leading slash: " + path);
9797
this.uriPath = path;
9898
return this;
9999
}

spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public ServletServerHttpRequest(MultiValueMap<String, String> headers, HttpServl
9090
super(initUri(request), request.getContextPath() + servletPath, initHeaders(headers, request));
9191

9292
Assert.notNull(bufferFactory, "'bufferFactory' must not be null");
93-
Assert.isTrue(bufferSize > 0, "'bufferSize' must be higher than 0");
93+
Assert.isTrue(bufferSize > 0, "'bufferSize' must be greater than 0");
9494

9595
this.request = request;
9696
this.bufferFactory = bufferFactory;

spring-web/src/main/java/org/springframework/web/filter/AbstractRequestLoggingFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 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.
@@ -209,7 +209,7 @@ protected Predicate<String> getHeaderPredicate() {
209209
* @since 3.0
210210
*/
211211
public void setMaxPayloadLength(int maxPayloadLength) {
212-
Assert.isTrue(maxPayloadLength >= 0, "'maxPayloadLength' should be larger than or equal to 0");
212+
Assert.isTrue(maxPayloadLength >= 0, "'maxPayloadLength' must be greater than or equal to 0");
213213
this.maxPayloadLength = maxPayloadLength;
214214
}
215215

spring-web/src/main/java/org/springframework/web/filter/RelativeRedirectFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 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.
@@ -53,7 +53,7 @@ public class RelativeRedirectFilter extends OncePerRequestFilter {
5353
*/
5454
public void setRedirectStatus(HttpStatus status) {
5555
Assert.notNull(status, "Property 'redirectStatus' is required");
56-
Assert.isTrue(status.is3xxRedirection(), "Not a redirect status code");
56+
Assert.isTrue(status.is3xxRedirection(), () -> "Not a redirect status code: " + status);
5757
this.redirectStatus = status;
5858
}
5959

spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ public String resolveAndCacheLookupPath(HttpServletRequest request) {
205205
* Return a previously {@link #getLookupPathForRequest resolved} lookupPath.
206206
* @param request the current request
207207
* @return the previously resolved lookupPath
208-
* @throws IllegalArgumentException if the not found
208+
* @throws IllegalArgumentException if the lookup path is not found
209209
* @since 5.3
210210
*/
211211
public static String getResolvedLookupPath(ServletRequest request) {
212212
String lookupPath = (String) request.getAttribute(PATH_ATTRIBUTE);
213-
Assert.notNull(lookupPath, "Expected lookupPath in request attribute \"" + PATH_ATTRIBUTE + "\".");
213+
Assert.notNull(lookupPath, () -> "Expected lookupPath in request attribute \"" + PATH_ATTRIBUTE + "\".");
214214
return lookupPath;
215215
}
216216

spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/CompositeRequestCondition.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 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.
@@ -31,8 +31,8 @@
3131
* ensure all conditions match a given request.
3232
*
3333
* <p>When {@code CompositeRequestCondition} instances are combined or compared
34-
* they are expected to (a) contain the same number of conditions and (b) that
35-
* conditions in the respective index are of the same type. It is acceptable to
34+
* is expected that (a) they contain the same number of conditions and (b)
35+
* conditions at the same index are of the same type. It is acceptable to
3636
* provide {@code null} conditions or no conditions at all to the constructor.
3737
*
3838
* @author Rossen Stoyanchev
@@ -105,7 +105,7 @@ private int getLength() {
105105

106106
/**
107107
* If one instance is empty, return the other.
108-
* If both instances have conditions, combine the individual conditions
108+
* <p>If both instances have conditions, combine the individual conditions
109109
* after ensuring they are of the same type and number.
110110
*/
111111
@Override
@@ -131,8 +131,8 @@ else if (isEmpty()) {
131131

132132
private void assertNumberOfConditions(CompositeRequestCondition other) {
133133
Assert.isTrue(getLength() == other.getLength(),
134-
"Cannot combine CompositeRequestConditions with a different number of conditions. " +
135-
ObjectUtils.nullSafeToString(this.requestConditions) + " and " +
134+
() -> "Cannot combine CompositeRequestConditions with a different number of conditions. " +
135+
ObjectUtils.nullSafeToString(this.requestConditions) + " and " +
136136
ObjectUtils.nullSafeToString(other.requestConditions));
137137
}
138138

spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public RedirectView(String redirectUrl, HttpStatus statusCode) {
9797
* {@link HttpStatus#PERMANENT_REDIRECT}.
9898
*/
9999
public void setStatusCode(HttpStatus statusCode) {
100-
Assert.isTrue(statusCode.is3xxRedirection(), "Not a redirect status code");
100+
Assert.isTrue(statusCode.is3xxRedirection(), () -> "Not a redirect status code: " + statusCode);
101101
this.statusCode = statusCode;
102102
}
103103

spring-webflux/src/main/java/org/springframework/web/reactive/socket/CloseStatus.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 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.
@@ -154,7 +154,7 @@ public CloseStatus(int code) {
154154
* @param reason the reason
155155
*/
156156
public CloseStatus(int code, @Nullable String reason) {
157-
Assert.isTrue((code >= 1000 && code < 5000), "Invalid status code");
157+
Assert.isTrue((code >= 1000 && code < 5000), () -> "Invalid status code: " + code);
158158
this.code = code;
159159
this.reason = reason;
160160
}

0 commit comments

Comments
 (0)