Avoid String allocations with Assert.isTrue()

This commit is contained in:
Sam Brannen 2022-11-05 14:40:45 +01:00
parent 902cdd1a2f
commit 5f02323b9c
27 changed files with 60 additions and 58 deletions

View File

@ -177,7 +177,7 @@ public abstract class DataBufferUtils {
if (options.length > 0) { if (options.length > 0) {
for (OpenOption option : options) { for (OpenOption option : options) {
Assert.isTrue(!(option == StandardOpenOption.APPEND || option == StandardOpenOption.WRITE), Assert.isTrue(!(option == StandardOpenOption.APPEND || option == StandardOpenOption.WRITE),
"'" + option + "' not allowed"); () -> "'" + option + "' not allowed");
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -103,7 +103,7 @@ final class DefaultRSocketRequesterBuilder implements RSocketRequester.Builder {
@Override @Override
public RSocketRequester.Builder metadataMimeType(MimeType mimeType) { public RSocketRequester.Builder metadataMimeType(MimeType mimeType) {
Assert.notNull(mimeType, "`metadataMimeType` is required"); Assert.notNull(mimeType, "'metadataMimeType' is required");
this.metadataMimeType = mimeType; this.metadataMimeType = mimeType;
return this; return this;
} }
@ -281,7 +281,7 @@ final class DefaultRSocketRequesterBuilder implements RSocketRequester.Builder {
Mono<DataBuffer> dataMono = Mono.empty(); Mono<DataBuffer> dataMono = Mono.empty();
if (data != null) { if (data != null) {
ReactiveAdapter adapter = strategies.reactiveAdapterRegistry().getAdapter(data.getClass()); ReactiveAdapter adapter = strategies.reactiveAdapterRegistry().getAdapter(data.getClass());
Assert.isTrue(adapter == null || !adapter.isMultiValue(), "Expected single value: " + data); Assert.isTrue(adapter == null || !adapter.isMultiValue(), () -> "Expected single value: " + data);
Mono<?> mono = (adapter != null ? Mono.from(adapter.toPublisher(data)) : Mono.just(data)); Mono<?> mono = (adapter != null ? Mono.from(adapter.toPublisher(data)) : Mono.just(data));
dataMono = mono.map(value -> { dataMono = mono.map(value -> {
ResolvableType type = ResolvableType.forClass(value.getClass()); ResolvableType type = ResolvableType.forClass(value.getClass());

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -141,7 +141,8 @@ final class MetadataEncoder {
} }
ReactiveAdapter adapter = this.strategies.reactiveAdapterRegistry().getAdapter(metadata.getClass()); ReactiveAdapter adapter = this.strategies.reactiveAdapterRegistry().getAdapter(metadata.getClass());
if (adapter != null) { if (adapter != null) {
Assert.isTrue(!adapter.isMultiValue(), "Expected single value: " + metadata); Object originalMetadata = metadata;
Assert.isTrue(!adapter.isMultiValue(), () -> "Expected single value: " + originalMetadata);
metadata = Mono.from(adapter.toPublisher(metadata)).defaultIfEmpty(NO_VALUE); metadata = Mono.from(adapter.toPublisher(metadata)).defaultIfEmpty(NO_VALUE);
this.hasAsyncValues = true; this.hasAsyncValues = true;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -421,7 +421,7 @@ public class RSocketMessageHandler extends MessageMappingMessageHandler {
String str = setupPayload.dataMimeType(); String str = setupPayload.dataMimeType();
MimeType dataMimeType = StringUtils.hasText(str) ? MimeTypeUtils.parseMimeType(str) : this.defaultDataMimeType; MimeType dataMimeType = StringUtils.hasText(str) ? MimeTypeUtils.parseMimeType(str) : this.defaultDataMimeType;
Assert.notNull(dataMimeType, "No `dataMimeType` in ConnectionSetupPayload and no default value"); Assert.notNull(dataMimeType, "No `dataMimeType` in ConnectionSetupPayload and no default value");
Assert.isTrue(isDataMimeTypeSupported(dataMimeType), "Data MimeType '" + dataMimeType + "' not supported"); Assert.isTrue(isDataMimeTypeSupported(dataMimeType), () -> "Data MimeType '" + dataMimeType + "' not supported");
str = setupPayload.metadataMimeType(); str = setupPayload.metadataMimeType();
MimeType metaMimeType = StringUtils.hasText(str) ? MimeTypeUtils.parseMimeType(str) : this.defaultMetadataMimeType; MimeType metaMimeType = StringUtils.hasText(str) ? MimeTypeUtils.parseMimeType(str) : this.defaultMetadataMimeType;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -138,7 +138,7 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String
*/ */
@Override @Override
public void send(Message<?> message) { public void send(Message<?> message) {
Assert.notNull(message, "Message is required"); Assert.notNull(message, "Message must not be null");
String destination = SimpMessageHeaderAccessor.getDestination(message.getHeaders()); String destination = SimpMessageHeaderAccessor.getDestination(message.getHeaders());
if (destination != null) { if (destination != null) {
sendInternal(message); sendInternal(message);
@ -224,7 +224,8 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String
throws MessagingException { throws MessagingException {
Assert.notNull(user, "User must not be null"); Assert.notNull(user, "User must not be null");
Assert.isTrue(!user.contains("%2F"), "Invalid sequence \"%2F\" in user name: " + user); String username = user;
Assert.isTrue(!user.contains("%2F"), () -> "Invalid sequence \"%2F\" in user name: " + username);
user = StringUtils.replace(user, "/", "%2F"); user = StringUtils.replace(user, "/", "%2F");
destination = destination.startsWith("/") ? destination : "/" + destination; destination = destination.startsWith("/") ? destination : "/" + destination;
super.convertAndSend(this.destinationPrefix + user + destination, payload, headers, postProcessor); super.convertAndSend(this.destinationPrefix + user + destination, payload, headers, postProcessor);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -148,7 +148,7 @@ public class OrderedMessageChannelDecorator implements MessageChannel {
public static void configureInterceptor(MessageChannel channel, boolean preserveOrder) { public static void configureInterceptor(MessageChannel channel, boolean preserveOrder) {
if (preserveOrder) { if (preserveOrder) {
Assert.isInstanceOf(ExecutorSubscribableChannel.class, channel, Assert.isInstanceOf(ExecutorSubscribableChannel.class, channel,
"An ExecutorSubscribableChannel is required for `preservePublishOrder`"); "An ExecutorSubscribableChannel is required for 'preservePublishOrder'");
ExecutorSubscribableChannel execChannel = (ExecutorSubscribableChannel) channel; ExecutorSubscribableChannel execChannel = (ExecutorSubscribableChannel) channel;
if (execChannel.getInterceptors().stream().noneMatch(i -> i instanceof CallbackInterceptor)) { if (execChannel.getInterceptors().stream().noneMatch(i -> i instanceof CallbackInterceptor)) {
execChannel.addInterceptor(0, new CallbackInterceptor()); execChannel.addInterceptor(0, new CallbackInterceptor());

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -211,7 +211,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
} }
Arrays.stream(acceptVersions).forEach(version -> Arrays.stream(acceptVersions).forEach(version ->
Assert.isTrue(version != null && (version.equals("1.1") || version.equals("1.2")), Assert.isTrue(version != null && (version.equals("1.1") || version.equals("1.2")),
"Invalid version: " + version)); () -> "Invalid version: " + version));
set(ACCEPT_VERSION, StringUtils.arrayToCommaDelimitedString(acceptVersions)); set(ACCEPT_VERSION, StringUtils.arrayToCommaDelimitedString(acceptVersions));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -203,7 +203,7 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver {
} }
Principal principal = SimpMessageHeaderAccessor.getUser(headers); Principal principal = SimpMessageHeaderAccessor.getUser(headers);
String user = (principal != null ? principal.getName() : null); String user = (principal != null ? principal.getName() : null);
Assert.isTrue(user == null || !user.contains("%2F"), "Invalid sequence \"%2F\" in user name: " + user); Assert.isTrue(user == null || !user.contains("%2F"), () -> "Invalid sequence \"%2F\" in user name: " + user);
Set<String> sessionIds = Collections.singleton(sessionId); Set<String> sessionIds = Collections.singleton(sessionId);
return new ParseResult(sourceDestination, actualDestination, sourceDestination, sessionIds, user); return new ParseResult(sourceDestination, actualDestination, sourceDestination, sessionIds, user);
} }

View File

@ -230,7 +230,7 @@ class DefaultWebTestClientBuilder implements WebTestClient.Builder {
@Override @Override
public WebTestClient.Builder entityExchangeResultConsumer(Consumer<EntityExchangeResult<?>> entityResultConsumer) { public WebTestClient.Builder entityExchangeResultConsumer(Consumer<EntityExchangeResult<?>> entityResultConsumer) {
Assert.notNull(entityResultConsumer, "`entityResultConsumer` is required"); Assert.notNull(entityResultConsumer, "'entityResultConsumer' is required");
this.entityResultConsumer = this.entityResultConsumer.andThen(entityResultConsumer); this.entityResultConsumer = this.entityResultConsumer.andThen(entityResultConsumer);
return this; return this;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -148,8 +148,8 @@ public class MockHttpServletRequestBuilder
private static URI initUri(String url, Object[] vars) { private static URI initUri(String url, Object[] vars) {
Assert.notNull(url, "'url' must not be null"); Assert.notNull(url, "'url' must not be null");
Assert.isTrue(url.startsWith("/") || url.startsWith("http://") || url.startsWith("https://"), "" + Assert.isTrue(url.startsWith("/") || url.startsWith("http://") || url.startsWith("https://"),
"'url' should start with a path or be a complete HTTP URL: " + url); () -> "'url' should start with a path or be a complete HTTP URL: " + url);
return UriComponentsBuilder.fromUriString(url).buildAndExpand(vars).encode().toUri(); return UriComponentsBuilder.fromUriString(url).buildAndExpand(vars).encode().toUri();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -42,8 +42,8 @@ public class HybridContextLoader extends AbstractGenericContextLoader {
@Override @Override
protected void validateMergedContextConfiguration(MergedContextConfiguration mergedConfig) { protected void validateMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
Assert.isTrue(mergedConfig.hasClasses() || mergedConfig.hasLocations(), getClass().getSimpleName() Assert.isTrue(mergedConfig.hasResources(),
+ " requires either classes or locations"); () -> getClass().getSimpleName() + " requires either classes or locations");
} }
@Override @Override

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -465,7 +465,7 @@ public final class ContentDisposition {
* @see <a href="https://tools.ietf.org/html/rfc5987">RFC 5987</a> * @see <a href="https://tools.ietf.org/html/rfc5987">RFC 5987</a>
*/ */
private static String decodeFilename(String filename, Charset charset) { private static String decodeFilename(String filename, Charset charset) {
Assert.notNull(filename, "'input' String` should not be null"); Assert.notNull(filename, "'input' String should not be null");
Assert.notNull(charset, "'charset' should not be null"); Assert.notNull(charset, "'charset' should not be null");
byte[] value = filename.getBytes(charset); byte[] value = filename.getBytes(charset);
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
@ -531,10 +531,10 @@ public final class ContentDisposition {
* @see <a href="https://tools.ietf.org/html/rfc5987">RFC 5987</a> * @see <a href="https://tools.ietf.org/html/rfc5987">RFC 5987</a>
*/ */
private static String encodeFilename(String input, Charset charset) { private static String encodeFilename(String input, Charset charset) {
Assert.notNull(input, "`input` is required"); Assert.notNull(input, "'input' is required");
Assert.notNull(charset, "`charset` is required"); Assert.notNull(charset, "'charset' is required");
Assert.isTrue(!StandardCharsets.US_ASCII.equals(charset), "ASCII does not require encoding"); Assert.isTrue(!StandardCharsets.US_ASCII.equals(charset), "ASCII does not require encoding");
Assert.isTrue(UTF_8.equals(charset) || ISO_8859_1.equals(charset), "Only UTF-8 and ISO-8859-1 supported."); Assert.isTrue(UTF_8.equals(charset) || ISO_8859_1.equals(charset), "Only UTF-8 and ISO-8859-1 are supported");
byte[] source = input.getBytes(charset); byte[] source = input.getBytes(charset);
int len = source.length; int len = source.length;
StringBuilder sb = new StringBuilder(len << 1); StringBuilder sb = new StringBuilder(len << 1);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -65,7 +65,7 @@ public abstract class HttpRange {
long contentLength = getLengthFor(resource); long contentLength = getLengthFor(resource);
long start = getRangeStart(contentLength); long start = getRangeStart(contentLength);
long end = getRangeEnd(contentLength); long end = getRangeEnd(contentLength);
Assert.isTrue(start < contentLength, "'position' exceeds the resource length " + contentLength); Assert.isTrue(start < contentLength, () -> "'position' exceeds the resource length " + contentLength);
return new ResourceRegion(resource, start, end - start + 1); return new ResourceRegion(resource, start, end - start + 1);
} }

View File

@ -231,7 +231,7 @@ public abstract class Jackson2CodecSupport {
JsonView annotation = getAnnotation(param, JsonView.class); JsonView annotation = getAnnotation(param, JsonView.class);
if (annotation != null) { if (annotation != null) {
Class<?>[] classes = annotation.value(); Class<?>[] classes = annotation.value();
Assert.isTrue(classes.length == 1, JSON_VIEW_HINT_ERROR + param); Assert.isTrue(classes.length == 1, () -> JSON_VIEW_HINT_ERROR + param);
hints = (hints != null ? hints : new HashMap<>(1)); hints = (hints != null ? hints : new HashMap<>(1));
hints.put(JSON_VIEW_HINT, classes[0]); hints.put(JSON_VIEW_HINT, classes[0]);
} }

View File

@ -128,7 +128,7 @@ public class BufferedImageHttpMessageConverter implements HttpMessageConverter<B
*/ */
public void setCacheDir(File cacheDir) { public void setCacheDir(File cacheDir) {
Assert.notNull(cacheDir, "'cacheDir' must not be null"); Assert.notNull(cacheDir, "'cacheDir' must not be null");
Assert.isTrue(cacheDir.isDirectory(), "'cacheDir' is not a directory"); Assert.isTrue(cacheDir.isDirectory(), () -> "'cacheDir' is not a directory: " + cacheDir);
this.cacheDir = cacheDir; this.cacheDir = cacheDir;
} }

View File

@ -436,7 +436,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
formData.forEach((name, values) -> { formData.forEach((name, values) -> {
if (name == null) { if (name == null) {
Assert.isTrue(CollectionUtils.isEmpty(values), "Null name in form data: " + formData); Assert.isTrue(CollectionUtils.isEmpty(values), () -> "Null name in form data: " + formData);
return; return;
} }
values.forEach(value -> { values.forEach(value -> {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -93,7 +93,7 @@ class DefaultServerHttpRequestBuilder implements ServerHttpRequest.Builder {
@Override @Override
public ServerHttpRequest.Builder path(String path) { public ServerHttpRequest.Builder path(String path) {
Assert.isTrue(path.startsWith("/"), "The path does not have a leading slash."); Assert.isTrue(path.startsWith("/"), () -> "The path does not have a leading slash: " + path);
this.uriPath = path; this.uriPath = path;
return this; return this;
} }

View File

@ -90,7 +90,7 @@ class ServletServerHttpRequest extends AbstractServerHttpRequest {
super(initUri(request), request.getContextPath() + servletPath, initHeaders(headers, request)); super(initUri(request), request.getContextPath() + servletPath, initHeaders(headers, request));
Assert.notNull(bufferFactory, "'bufferFactory' must not be null"); Assert.notNull(bufferFactory, "'bufferFactory' must not be null");
Assert.isTrue(bufferSize > 0, "'bufferSize' must be higher than 0"); Assert.isTrue(bufferSize > 0, "'bufferSize' must be greater than 0");
this.request = request; this.request = request;
this.bufferFactory = bufferFactory; this.bufferFactory = bufferFactory;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -209,7 +209,7 @@ public abstract class AbstractRequestLoggingFilter extends OncePerRequestFilter
* @since 3.0 * @since 3.0
*/ */
public void setMaxPayloadLength(int maxPayloadLength) { public void setMaxPayloadLength(int maxPayloadLength) {
Assert.isTrue(maxPayloadLength >= 0, "'maxPayloadLength' should be larger than or equal to 0"); Assert.isTrue(maxPayloadLength >= 0, "'maxPayloadLength' must be greater than or equal to 0");
this.maxPayloadLength = maxPayloadLength; this.maxPayloadLength = maxPayloadLength;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -53,7 +53,7 @@ public class RelativeRedirectFilter extends OncePerRequestFilter {
*/ */
public void setRedirectStatus(HttpStatus status) { public void setRedirectStatus(HttpStatus status) {
Assert.notNull(status, "Property 'redirectStatus' is required"); Assert.notNull(status, "Property 'redirectStatus' is required");
Assert.isTrue(status.is3xxRedirection(), "Not a redirect status code"); Assert.isTrue(status.is3xxRedirection(), () -> "Not a redirect status code: " + status);
this.redirectStatus = status; this.redirectStatus = status;
} }

View File

@ -205,12 +205,12 @@ public class UrlPathHelper {
* Return a previously {@link #getLookupPathForRequest resolved} lookupPath. * Return a previously {@link #getLookupPathForRequest resolved} lookupPath.
* @param request the current request * @param request the current request
* @return the previously resolved lookupPath * @return the previously resolved lookupPath
* @throws IllegalArgumentException if the not found * @throws IllegalArgumentException if the lookup path is not found
* @since 5.3 * @since 5.3
*/ */
public static String getResolvedLookupPath(ServletRequest request) { public static String getResolvedLookupPath(ServletRequest request) {
String lookupPath = (String) request.getAttribute(PATH_ATTRIBUTE); String lookupPath = (String) request.getAttribute(PATH_ATTRIBUTE);
Assert.notNull(lookupPath, "Expected lookupPath in request attribute \"" + PATH_ATTRIBUTE + "\"."); Assert.notNull(lookupPath, () -> "Expected lookupPath in request attribute \"" + PATH_ATTRIBUTE + "\".");
return lookupPath; return lookupPath;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,8 +31,8 @@ import org.springframework.web.server.ServerWebExchange;
* ensure all conditions match a given request. * ensure all conditions match a given request.
* *
* <p>When {@code CompositeRequestCondition} instances are combined or compared * <p>When {@code CompositeRequestCondition} instances are combined or compared
* they are expected to (a) contain the same number of conditions and (b) that * is expected that (a) they contain the same number of conditions and (b)
* conditions in the respective index are of the same type. It is acceptable to * conditions at the same index are of the same type. It is acceptable to
* provide {@code null} conditions or no conditions at all to the constructor. * provide {@code null} conditions or no conditions at all to the constructor.
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
@ -105,7 +105,7 @@ public class CompositeRequestCondition extends AbstractRequestCondition<Composit
/** /**
* If one instance is empty, return the other. * If one instance is empty, return the other.
* If both instances have conditions, combine the individual conditions * <p>If both instances have conditions, combine the individual conditions
* after ensuring they are of the same type and number. * after ensuring they are of the same type and number.
*/ */
@Override @Override
@ -131,7 +131,7 @@ public class CompositeRequestCondition extends AbstractRequestCondition<Composit
private void assertNumberOfConditions(CompositeRequestCondition other) { private void assertNumberOfConditions(CompositeRequestCondition other) {
Assert.isTrue(getLength() == other.getLength(), Assert.isTrue(getLength() == other.getLength(),
"Cannot combine CompositeRequestConditions with a different number of conditions. " + () -> "Cannot combine CompositeRequestConditions with a different number of conditions. " +
ObjectUtils.nullSafeToString(this.requestConditions) + " and " + ObjectUtils.nullSafeToString(this.requestConditions) + " and " +
ObjectUtils.nullSafeToString(other.requestConditions)); ObjectUtils.nullSafeToString(other.requestConditions));
} }

View File

@ -97,7 +97,7 @@ public class RedirectView extends AbstractUrlBasedView {
* {@link HttpStatus#PERMANENT_REDIRECT}. * {@link HttpStatus#PERMANENT_REDIRECT}.
*/ */
public void setStatusCode(HttpStatus statusCode) { public void setStatusCode(HttpStatus statusCode) {
Assert.isTrue(statusCode.is3xxRedirection(), "Not a redirect status code"); Assert.isTrue(statusCode.is3xxRedirection(), () -> "Not a redirect status code: " + statusCode);
this.statusCode = statusCode; this.statusCode = statusCode;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -154,7 +154,7 @@ public final class CloseStatus {
* @param reason the reason * @param reason the reason
*/ */
public CloseStatus(int code, @Nullable String reason) { public CloseStatus(int code, @Nullable String reason) {
Assert.isTrue((code >= 1000 && code < 5000), "Invalid status code"); Assert.isTrue((code >= 1000 && code < 5000), () -> "Invalid status code: " + code);
this.code = code; this.code = code;
this.reason = reason; this.reason = reason;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -54,7 +54,7 @@ public class RedirectViewControllerRegistration {
* will select {@code HttpStatus.MOVED_TEMPORARILY (302)} by default. * will select {@code HttpStatus.MOVED_TEMPORARILY (302)} by default.
*/ */
public RedirectViewControllerRegistration setStatusCode(HttpStatus statusCode) { public RedirectViewControllerRegistration setStatusCode(HttpStatus statusCode) {
Assert.isTrue(statusCode.is3xxRedirection(), "Not a redirect status code"); Assert.isTrue(statusCode.is3xxRedirection(), () -> "Not a redirect status code: " + statusCode);
this.redirectView.setStatusCode(statusCode); this.redirectView.setStatusCode(statusCode);
return this; return this;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -133,7 +133,7 @@ public class CompositeRequestCondition extends AbstractRequestCondition<Composit
private void assertNumberOfConditions(CompositeRequestCondition other) { private void assertNumberOfConditions(CompositeRequestCondition other) {
Assert.isTrue(getLength() == other.getLength(), Assert.isTrue(getLength() == other.getLength(),
"Cannot combine CompositeRequestConditions with a different number of conditions. " + () -> "Cannot combine CompositeRequestConditions with a different number of conditions. " +
ObjectUtils.nullSafeToString(this.requestConditions) + " and " + ObjectUtils.nullSafeToString(this.requestConditions) + " and " +
ObjectUtils.nullSafeToString(other.requestConditions)); ObjectUtils.nullSafeToString(other.requestConditions));
} }

View File

@ -168,7 +168,7 @@ public final class CloseStatus implements Serializable {
* @param reason the reason * @param reason the reason
*/ */
public CloseStatus(int code, @Nullable String reason) { public CloseStatus(int code, @Nullable String reason) {
Assert.isTrue((code >= 1000 && code < 5000), "Invalid status code"); Assert.isTrue((code >= 1000 && code < 5000), () -> "Invalid status code: " + code);
this.code = code; this.code = code;
this.reason = reason; this.reason = reason;
} }