Browse Source

Deprecate obsolete Assert APIs for removal in 6.1

See gh-29449
pull/27328/merge
Sam Brannen 3 years ago
parent
commit
af170f693a
  1. 57
      spring-core/src/main/java/org/springframework/util/Assert.java

57
spring-core/src/main/java/org/springframework/util/Assert.java

@ -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.
@ -101,9 +101,10 @@ public abstract class Assert {
/** /**
* Assert a boolean expression, throwing an {@code IllegalStateException} * Assert a boolean expression, throwing an {@code IllegalStateException}
* if the expression evaluates to {@code false}. * if the expression evaluates to {@code false}.
* @deprecated as of 4.3.7, in favor of {@link #state(boolean, String)} * @deprecated as of 4.3.7, in favor of {@link #state(boolean, String)};
* to be removed in 6.1
*/ */
@Deprecated @Deprecated(forRemoval = true)
public static void state(boolean expression) { public static void state(boolean expression) {
state(expression, "[Assertion failed] - this state invariant must be true"); state(expression, "[Assertion failed] - this state invariant must be true");
} }
@ -143,9 +144,10 @@ public abstract class Assert {
/** /**
* Assert a boolean expression, throwing an {@code IllegalArgumentException} * Assert a boolean expression, throwing an {@code IllegalArgumentException}
* if the expression evaluates to {@code false}. * if the expression evaluates to {@code false}.
* @deprecated as of 4.3.7, in favor of {@link #isTrue(boolean, String)} * @deprecated as of 4.3.7, in favor of {@link #isTrue(boolean, String)};
* to be removed in 6.1
*/ */
@Deprecated @Deprecated(forRemoval = true)
public static void isTrue(boolean expression) { public static void isTrue(boolean expression) {
isTrue(expression, "[Assertion failed] - this expression must be true"); isTrue(expression, "[Assertion failed] - this expression must be true");
} }
@ -182,9 +184,10 @@ public abstract class Assert {
/** /**
* Assert that an object is {@code null}. * Assert that an object is {@code null}.
* @deprecated as of 4.3.7, in favor of {@link #isNull(Object, String)} * @deprecated as of 4.3.7, in favor of {@link #isNull(Object, String)};
* to be removed in 6.1
*/ */
@Deprecated @Deprecated(forRemoval = true)
public static void isNull(@Nullable Object object) { public static void isNull(@Nullable Object object) {
isNull(object, "[Assertion failed] - the object argument must be null"); isNull(object, "[Assertion failed] - the object argument must be null");
} }
@ -222,9 +225,10 @@ public abstract class Assert {
/** /**
* Assert that an object is not {@code null}. * Assert that an object is not {@code null}.
* @deprecated as of 4.3.7, in favor of {@link #notNull(Object, String)} * @deprecated as of 4.3.7, in favor of {@link #notNull(Object, String)};
* to be removed in 6.1
*/ */
@Deprecated @Deprecated(forRemoval = true)
public static void notNull(@Nullable Object object) { public static void notNull(@Nullable Object object) {
notNull(object, "[Assertion failed] - this argument is required; it must not be null"); notNull(object, "[Assertion failed] - this argument is required; it must not be null");
} }
@ -267,9 +271,10 @@ public abstract class Assert {
/** /**
* Assert that the given String is not empty; that is, * Assert that the given String is not empty; that is,
* it must not be {@code null} and not the empty String. * it must not be {@code null} and not the empty String.
* @deprecated as of 4.3.7, in favor of {@link #hasLength(String, String)} * @deprecated as of 4.3.7, in favor of {@link #hasLength(String, String)};
* to be removed in 6.1
*/ */
@Deprecated @Deprecated(forRemoval = true)
public static void hasLength(@Nullable String text) { public static void hasLength(@Nullable String text) {
hasLength(text, hasLength(text,
"[Assertion failed] - this String argument must have length; it must not be null or empty"); "[Assertion failed] - this String argument must have length; it must not be null or empty");
@ -313,9 +318,10 @@ public abstract class Assert {
/** /**
* Assert that the given String contains valid text content; that is, it must not * Assert that the given String contains valid text content; that is, it must not
* be {@code null} and must contain at least one non-whitespace character. * be {@code null} and must contain at least one non-whitespace character.
* @deprecated as of 4.3.7, in favor of {@link #hasText(String, String)} * @deprecated as of 4.3.7, in favor of {@link #hasText(String, String)};
* to be removed in 6.1
*/ */
@Deprecated @Deprecated(forRemoval = true)
public static void hasText(@Nullable String text) { public static void hasText(@Nullable String text) {
hasText(text, hasText(text,
"[Assertion failed] - this String argument must have text; it must not be null, empty, or blank"); "[Assertion failed] - this String argument must have text; it must not be null, empty, or blank");
@ -357,9 +363,10 @@ public abstract class Assert {
/** /**
* Assert that the given text does not contain the given substring. * Assert that the given text does not contain the given substring.
* @deprecated as of 4.3.7, in favor of {@link #doesNotContain(String, String, String)} * @deprecated as of 4.3.7, in favor of {@link #doesNotContain(String, String, String)};
* to be removed in 6.1
*/ */
@Deprecated @Deprecated(forRemoval = true)
public static void doesNotContain(@Nullable String textToSearch, String substring) { public static void doesNotContain(@Nullable String textToSearch, String substring) {
doesNotContain(textToSearch, substring, doesNotContain(textToSearch, substring,
() -> "[Assertion failed] - this String argument must not contain the substring [" + substring + "]"); () -> "[Assertion failed] - this String argument must not contain the substring [" + substring + "]");
@ -400,9 +407,10 @@ public abstract class Assert {
/** /**
* Assert that an array contains elements; that is, it must not be * Assert that an array contains elements; that is, it must not be
* {@code null} and must contain at least one element. * {@code null} and must contain at least one element.
* @deprecated as of 4.3.7, in favor of {@link #notEmpty(Object[], String)} * @deprecated as of 4.3.7, in favor of {@link #notEmpty(Object[], String)};
* to be removed in 6.1
*/ */
@Deprecated @Deprecated(forRemoval = true)
public static void notEmpty(@Nullable Object[] array) { public static void notEmpty(@Nullable Object[] array) {
notEmpty(array, "[Assertion failed] - this array must not be empty: it must contain at least 1 element"); notEmpty(array, "[Assertion failed] - this array must not be empty: it must contain at least 1 element");
} }
@ -449,9 +457,10 @@ public abstract class Assert {
/** /**
* Assert that an array contains no {@code null} elements. * Assert that an array contains no {@code null} elements.
* @deprecated as of 4.3.7, in favor of {@link #noNullElements(Object[], String)} * @deprecated as of 4.3.7, in favor of {@link #noNullElements(Object[], String)};
* to be removed in 6.1
*/ */
@Deprecated @Deprecated(forRemoval = true)
public static void noNullElements(@Nullable Object[] array) { public static void noNullElements(@Nullable Object[] array) {
noNullElements(array, "[Assertion failed] - this array must not contain any null elements"); noNullElements(array, "[Assertion failed] - this array must not contain any null elements");
} }
@ -493,9 +502,10 @@ public abstract class Assert {
/** /**
* Assert that a collection contains elements; that is, it must not be * Assert that a collection contains elements; that is, it must not be
* {@code null} and must contain at least one element. * {@code null} and must contain at least one element.
* @deprecated as of 4.3.7, in favor of {@link #notEmpty(Collection, String)} * @deprecated as of 4.3.7, in favor of {@link #notEmpty(Collection, String)};
* to be removed in 6.1
*/ */
@Deprecated @Deprecated(forRemoval = true)
public static void notEmpty(@Nullable Collection<?> collection) { public static void notEmpty(@Nullable Collection<?> collection) {
notEmpty(collection, notEmpty(collection,
"[Assertion failed] - this collection must not be empty: it must contain at least 1 element"); "[Assertion failed] - this collection must not be empty: it must contain at least 1 element");
@ -577,9 +587,10 @@ public abstract class Assert {
/** /**
* Assert that a Map contains entries; that is, it must not be {@code null} * Assert that a Map contains entries; that is, it must not be {@code null}
* and must contain at least one entry. * and must contain at least one entry.
* @deprecated as of 4.3.7, in favor of {@link #notEmpty(Map, String)} * @deprecated as of 4.3.7, in favor of {@link #notEmpty(Map, String)};
* to be removed in 6.1
*/ */
@Deprecated @Deprecated(forRemoval = true)
public static void notEmpty(@Nullable Map<?, ?> map) { public static void notEmpty(@Nullable Map<?, ?> map) {
notEmpty(map, "[Assertion failed] - this map must not be empty; it must contain at least one entry"); notEmpty(map, "[Assertion failed] - this map must not be empty; it must contain at least one entry");
} }

Loading…
Cancel
Save