From af170f693a921f1d4e79205cdf49e2644f12ddaa Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Tue, 8 Nov 2022 16:55:06 +0100 Subject: [PATCH] Deprecate obsolete Assert APIs for removal in 6.1 See gh-29449 --- .../java/org/springframework/util/Assert.java | 57 +++++++++++-------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/util/Assert.java b/spring-core/src/main/java/org/springframework/util/Assert.java index 786b9b9463e..c006ea6634f 100644 --- a/spring-core/src/main/java/org/springframework/util/Assert.java +++ b/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"); * 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} * 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) { 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} * 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) { isTrue(expression, "[Assertion failed] - this expression must be true"); } @@ -182,9 +184,10 @@ public abstract class Assert { /** * 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) { 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}. - * @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) { 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, * 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) { hasLength(text, "[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 * 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) { hasText(text, "[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. - * @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) { doesNotContain(textToSearch, 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 * {@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) { 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. - * @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) { 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 * {@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) { notEmpty(collection, "[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} * 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) { notEmpty(map, "[Assertion failed] - this map must not be empty; it must contain at least one entry"); }