Use consistent wording in precondition error messages

This commit is contained in:
Sam Brannen
2022-11-06 11:57:34 +01:00
parent 711a63adca
commit 2aa78889d2
27 changed files with 88 additions and 86 deletions

View File

@@ -51,6 +51,7 @@ public class ReflectionHintsPredicates {
ReflectionHintsPredicates() {
}
/**
* Return a predicate that checks whether a reflection hint is registered for the given type.
* <p>The returned type exposes additional methods that refine the predicate behavior.
@@ -58,7 +59,7 @@ public class ReflectionHintsPredicates {
* @return the {@link RuntimeHints} predicate
*/
public TypeHintPredicate onType(TypeReference typeReference) {
Assert.notNull(typeReference, "'typeReference' should not be null");
Assert.notNull(typeReference, "'typeReference' must not be null");
return new TypeHintPredicate(typeReference);
}
@@ -69,7 +70,7 @@ public class ReflectionHintsPredicates {
* @return the {@link RuntimeHints} predicate
*/
public TypeHintPredicate onType(Class<?> type) {
Assert.notNull(type, "'type' should not be null");
Assert.notNull(type, "'type' must not be null");
return new TypeHintPredicate(TypeReference.of(type));
}
@@ -81,7 +82,7 @@ public class ReflectionHintsPredicates {
* @return the {@link RuntimeHints} predicate
*/
public ConstructorHintPredicate onConstructor(Constructor<?> constructor) {
Assert.notNull(constructor, "'constructor' should not be null");
Assert.notNull(constructor, "'constructor' must not be null");
return new ConstructorHintPredicate(constructor);
}
@@ -93,7 +94,7 @@ public class ReflectionHintsPredicates {
* @return the {@link RuntimeHints} predicate
*/
public MethodHintPredicate onMethod(Method method) {
Assert.notNull(method, "'method' should not be null");
Assert.notNull(method, "'method' must not be null");
return new MethodHintPredicate(method);
}
@@ -108,8 +109,8 @@ public class ReflectionHintsPredicates {
* @throws IllegalArgumentException if the method cannot be found or if multiple methods are found with the same name.
*/
public MethodHintPredicate onMethod(Class<?> type, String methodName) {
Assert.notNull(type, "'type' should not be null");
Assert.hasText(methodName, "'methodName' should not be empty");
Assert.notNull(type, "'type' must not be null");
Assert.hasText(methodName, "'methodName' must not be empty");
return new MethodHintPredicate(getMethod(type, methodName));
}
@@ -125,8 +126,8 @@ public class ReflectionHintsPredicates {
* @throws IllegalArgumentException if the method cannot be found or if multiple methods are found with the same name.
*/
public MethodHintPredicate onMethod(String className, String methodName) throws ClassNotFoundException {
Assert.hasText(className, "'className' should not be empty");
Assert.hasText(methodName, "'methodName' should not be empty");
Assert.hasText(className, "'className' must not be empty");
Assert.hasText(methodName, "'methodName' must not be empty");
return onMethod(Class.forName(className), methodName);
}
@@ -155,8 +156,8 @@ public class ReflectionHintsPredicates {
* @throws IllegalArgumentException if a field cannot be found with the given name.
*/
public FieldHintPredicate onField(Class<?> type, String fieldName) {
Assert.notNull(type, "'type' should not be null");
Assert.hasText(fieldName, "'fieldName' should not be empty");
Assert.notNull(type, "'type' must not be null");
Assert.hasText(fieldName, "'fieldName' must not be empty");
Field field = ReflectionUtils.findField(type, fieldName);
if (field == null) {
throw new IllegalArgumentException("No field named '%s' on class %s".formatted(fieldName, type.getName()));
@@ -176,8 +177,8 @@ public class ReflectionHintsPredicates {
* @throws IllegalArgumentException if a field cannot be found with the given name.
*/
public FieldHintPredicate onField(String className, String fieldName) throws ClassNotFoundException {
Assert.hasText(className, "'className' should not be empty");
Assert.hasText(fieldName, "'fieldName' should not be empty");
Assert.hasText(className, "'className' must not be empty");
Assert.hasText(fieldName, "'fieldName' must not be empty");
return onField(Class.forName(className), fieldName);
}
@@ -189,7 +190,7 @@ public class ReflectionHintsPredicates {
* @return the {@link RuntimeHints} predicate
*/
public FieldHintPredicate onField(Field field) {
Assert.notNull(field, "'field' should not be null");
Assert.notNull(field, "'field' must not be null");
return new FieldHintPredicate(field);
}
@@ -218,7 +219,7 @@ public class ReflectionHintsPredicates {
* @return the refined {@link RuntimeHints} predicate
*/
public Predicate<RuntimeHints> withMemberCategory(MemberCategory memberCategory) {
Assert.notNull(memberCategory, "'memberCategory' should not be null");
Assert.notNull(memberCategory, "'memberCategory' must not be null");
return this.and(hints -> getTypeHint(hints).getMemberCategories().contains(memberCategory));
}
@@ -228,7 +229,7 @@ public class ReflectionHintsPredicates {
* @return the refined {@link RuntimeHints} predicate
*/
public Predicate<RuntimeHints> withMemberCategories(MemberCategory... memberCategories) {
Assert.notEmpty(memberCategories, "'memberCategories' should not be empty");
Assert.notEmpty(memberCategories, "'memberCategories' must not be empty");
return this.and(hints -> getTypeHint(hints).getMemberCategories().containsAll(Arrays.asList(memberCategories)));
}
@@ -238,7 +239,7 @@ public class ReflectionHintsPredicates {
* @return the refined {@link RuntimeHints} predicate
*/
public Predicate<RuntimeHints> withAnyMemberCategory(MemberCategory... memberCategories) {
Assert.notEmpty(memberCategories, "'memberCategories' should not be empty");
Assert.notEmpty(memberCategories, "'memberCategories' must not be empty");
return this.and(hints -> Arrays.stream(memberCategories)
.anyMatch(memberCategory -> getTypeHint(hints).getMemberCategories().contains(memberCategory)));
}

View File

@@ -35,6 +35,7 @@ public class SerializationHintsPredicates {
SerializationHintsPredicates() {
}
/**
* Return a predicate that checks whether a {@link SerializationHints
* serialization hint} is registered for the given type.
@@ -43,7 +44,7 @@ public class SerializationHintsPredicates {
* @see java.lang.reflect.Proxy
*/
public Predicate<RuntimeHints> onType(Class<?> type) {
Assert.notNull(type, "'type' should not be null");
Assert.notNull(type, "'type' must not be null");
return onType(TypeReference.of(type));
}
@@ -55,7 +56,7 @@ public class SerializationHintsPredicates {
* @see java.lang.reflect.Proxy
*/
public Predicate<RuntimeHints> onType(TypeReference typeReference) {
Assert.notNull(typeReference, "'typeReference' should not be null");
Assert.notNull(typeReference, "'typeReference' must not be null");
return hints -> hints.serialization().javaSerializationHints().anyMatch(
hint -> hint.getType().equals(typeReference));
}

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");
* you may not use this file except in compliance with the License.
@@ -57,7 +57,7 @@ public interface Converter<S, T> {
* @since 5.3
*/
default <U> Converter<S, U> andThen(Converter<? super T, ? extends U> after) {
Assert.notNull(after, "After Converter must not be null");
Assert.notNull(after, "'after' Converter must not be null");
return (S s) -> {
T initialResult = convert(s);
return (initialResult != null ? after.convert(initialResult) : null);

View File

@@ -114,7 +114,7 @@ public class ConvertingComparator<S, T> implements Comparator<S> {
public ConversionServiceConverter(ConversionService conversionService, Class<? extends T> targetType) {
Assert.notNull(conversionService, "ConversionService must not be null");
Assert.notNull(targetType, "TargetType must not be null");
Assert.notNull(targetType, "'targetType' must not be null");
this.conversionService = conversionService;
this.targetType = targetType;
}

View File

@@ -100,7 +100,7 @@ public abstract class DataBufferUtils {
Callable<ReadableByteChannel> channelSupplier, DataBufferFactory bufferFactory, int bufferSize) {
Assert.notNull(channelSupplier, "'channelSupplier' must not be null");
Assert.notNull(bufferFactory, "'dataBufferFactory' must not be null");
Assert.notNull(bufferFactory, "'bufferFactory' must not be null");
Assert.isTrue(bufferSize > 0, "'bufferSize' must be > 0");
return Flux.using(channelSupplier,
@@ -140,7 +140,7 @@ public abstract class DataBufferUtils {
DataBufferFactory bufferFactory, int bufferSize) {
Assert.notNull(channelSupplier, "'channelSupplier' must not be null");
Assert.notNull(bufferFactory, "'dataBufferFactory' must not be null");
Assert.notNull(bufferFactory, "'bufferFactory' must not be null");
Assert.isTrue(position >= 0, "'position' must be >= 0");
Assert.isTrue(bufferSize > 0, "'bufferSize' must be > 0");
@@ -172,7 +172,7 @@ public abstract class DataBufferUtils {
Path path, DataBufferFactory bufferFactory, int bufferSize, OpenOption... options) {
Assert.notNull(path, "Path must not be null");
Assert.notNull(bufferFactory, "BufferFactory must not be null");
Assert.notNull(bufferFactory, "DataBufferFactory must not be null");
Assert.isTrue(bufferSize > 0, "'bufferSize' must be > 0");
if (options.length > 0) {
for (OpenOption option : options) {
@@ -420,7 +420,7 @@ public abstract class DataBufferUtils {
@SuppressWarnings("unchecked")
public static <T extends DataBuffer> Flux<T> takeUntilByteCount(Publisher<T> publisher, long maxByteCount) {
Assert.notNull(publisher, "Publisher must not be null");
Assert.isTrue(maxByteCount >= 0, "'maxByteCount' must be a positive number");
Assert.isTrue(maxByteCount >= 0, "'maxByteCount' must be >= 0");
return Flux.defer(() -> {
AtomicLong countDown = new AtomicLong(maxByteCount);
@@ -453,7 +453,7 @@ public abstract class DataBufferUtils {
*/
public static <T extends DataBuffer> Flux<T> skipUntilByteCount(Publisher<T> publisher, long maxByteCount) {
Assert.notNull(publisher, "Publisher must not be null");
Assert.isTrue(maxByteCount >= 0, "'maxByteCount' must be a positive number");
Assert.isTrue(maxByteCount >= 0, "'maxByteCount' must be >= 0");
return Flux.defer(() -> {
AtomicLong countDown = new AtomicLong(maxByteCount);
@@ -590,7 +590,7 @@ public abstract class DataBufferUtils {
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Mono<DataBuffer> join(Publisher<? extends DataBuffer> buffers, int maxByteCount) {
Assert.notNull(buffers, "'dataBuffers' must not be null");
Assert.notNull(buffers, "'buffers' must not be null");
if (buffers instanceof Mono mono) {
return mono;

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");
* you may not use this file except in compliance with the License.
@@ -45,8 +45,8 @@ public class ResourceRegion {
*/
public ResourceRegion(Resource resource, long position, long count) {
Assert.notNull(resource, "Resource must not be null");
Assert.isTrue(position >= 0, "'position' must be larger than or equal to 0");
Assert.isTrue(count >= 0, "'count' must be larger than or equal to 0");
Assert.isTrue(position >= 0, "'position' must be greater than or equal to 0");
Assert.isTrue(count >= 0, "'count' must be greater than or equal to 0");
this.resource = resource;
this.position = position;
this.count = count;

View File

@@ -113,7 +113,7 @@ public class AntPathMatcher implements PathMatcher {
* @since 4.1
*/
public AntPathMatcher(String pathSeparator) {
Assert.notNull(pathSeparator, "'pathSeparator' is required");
Assert.notNull(pathSeparator, "'pathSeparator' must not be null");
this.pathSeparator = pathSeparator;
this.pathSeparatorPatternCache = new PathSeparatorPatternCache(pathSeparator);
}

View File

@@ -29,7 +29,6 @@ import java.util.function.Function;
import org.springframework.lang.Nullable;
/**
* Simple LRU (Least Recently Used) cache, bounded by a specified cache capacity.
* <p>This is a simplified, opinionated implementation of a LRU cache for internal
@@ -81,7 +80,7 @@ public final class ConcurrentLruCache<K, V> {
}
private ConcurrentLruCache(int capacity, Function<K, V> generator, int concurrencyLevel) {
Assert.isTrue(capacity > 0, "Capacity should be > 0");
Assert.isTrue(capacity > 0, "Capacity must be > 0");
this.capacity = capacity;
this.cache = new ConcurrentHashMap<>(16, 0.75f, concurrencyLevel);
this.generator = generator;
@@ -106,8 +105,8 @@ public final class ConcurrentLruCache<K, V> {
}
private void put(K key, V value) {
Assert.notNull(key, "key should not be null");
Assert.notNull(value, "value should not be null");
Assert.notNull(key, "key must not be null");
Assert.notNull(value, "value must not be null");
final CacheEntry<V> cacheEntry = new CacheEntry<>(value, CacheEntryState.ACTIVE);
final Node<K, V> node = new Node<>(key, cacheEntry);
final Node<K, V> prior = this.cache.putIfAbsent(node.key, node);

View File

@@ -85,7 +85,7 @@ public class NullSafeComparator<T> implements Comparator<T> {
* @param nullsLow whether to treat nulls lower or higher than non-null objects
*/
public NullSafeComparator(Comparator<T> comparator, boolean nullsLow) {
Assert.notNull(comparator, "Non-null Comparator is required");
Assert.notNull(comparator, "Comparator must not be null");
this.nonNullComparator = comparator;
this.nullsLow = nullsLow;
}

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");
* you may not use this file except in compliance with the License.
@@ -49,7 +49,7 @@ public class SimpleNamespaceContext implements NamespaceContext {
@Override
public String getNamespaceURI(String prefix) {
Assert.notNull(prefix, "No prefix given");
Assert.notNull(prefix, "'prefix' must not be null");
if (XMLConstants.XML_NS_PREFIX.equals(prefix)) {
return XMLConstants.XML_NS_URI;
}
@@ -78,7 +78,7 @@ public class SimpleNamespaceContext implements NamespaceContext {
}
private Set<String> getPrefixesSet(String namespaceUri) {
Assert.notNull(namespaceUri, "No namespaceUri given");
Assert.notNull(namespaceUri, "'namespaceUri' must not be null");
if (this.defaultNamespaceUri.equals(namespaceUri)) {
return Collections.singleton(XMLConstants.DEFAULT_NS_PREFIX);
}
@@ -114,11 +114,11 @@ public class SimpleNamespaceContext implements NamespaceContext {
/**
* Bind the given prefix to the given namespace.
* @param prefix the namespace prefix
* @param namespaceUri the namespace uri
* @param namespaceUri the namespace URI
*/
public void bindNamespaceUri(String prefix, String namespaceUri) {
Assert.notNull(prefix, "No prefix given");
Assert.notNull(namespaceUri, "No namespaceUri given");
Assert.notNull(prefix, "'prefix' must not be null");
Assert.notNull(namespaceUri, "'namespaceUri' must not be null");
if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) {
this.defaultNamespaceUri = namespaceUri;
}