Browse Source

Fix example in Javadoc for Assert.notNull(object, messageSupplier)

Closes gh-25774
5.0.x
Juergen Hoeller 5 years ago
parent
commit
62fef5a6ce
  1. 41
      spring-core/src/main/java/org/springframework/util/Assert.java

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2020 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.
@ -80,8 +80,8 @@ public abstract class Assert {
* <p>Call {@link #isTrue} if you wish to throw an {@code IllegalArgumentException} * <p>Call {@link #isTrue} if you wish to throw an {@code IllegalArgumentException}
* on an assertion failure. * on an assertion failure.
* <pre class="code"> * <pre class="code">
* Assert.state(id == null, * Assert.state(entity.getId() == null,
* () -&gt; "ID for " + entity.getName() + " must not already be initialized"); * () -&gt; "ID for entity " + entity.getName() + " must not already be initialized");
* </pre> * </pre>
* @param expression a boolean expression * @param expression a boolean expression
* @param messageSupplier a supplier for the exception message to use if the * @param messageSupplier a supplier for the exception message to use if the
@ -96,6 +96,8 @@ 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)}
*/ */
@Deprecated @Deprecated
@ -136,6 +138,8 @@ 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)}
*/ */
@Deprecated @Deprecated
@ -174,6 +178,7 @@ 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)}
*/ */
@Deprecated @Deprecated
@ -197,7 +202,8 @@ public abstract class Assert {
/** /**
* Assert that an object is not {@code null}. * Assert that an object is not {@code null}.
* <pre class="code"> * <pre class="code">
* Assert.notNull(clazz, () -&gt; "The class '" + clazz.getName() + "' must not be null"); * Assert.notNull(entity.getId(),
* () -&gt; "ID for entity " + entity.getName() + " must not be null");
* </pre> * </pre>
* @param object the object to check * @param object the object to check
* @param messageSupplier a supplier for the exception message to use if the * @param messageSupplier a supplier for the exception message to use if the
@ -212,6 +218,7 @@ 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)}
*/ */
@Deprecated @Deprecated
@ -225,8 +232,8 @@ public abstract class Assert {
* <pre class="code">Assert.hasLength(name, "Name must not be empty");</pre> * <pre class="code">Assert.hasLength(name, "Name must not be empty");</pre>
* @param text the String to check * @param text the String to check
* @param message the exception message to use if the assertion fails * @param message the exception message to use if the assertion fails
* @see StringUtils#hasLength
* @throws IllegalArgumentException if the text is empty * @throws IllegalArgumentException if the text is empty
* @see StringUtils#hasLength
*/ */
public static void hasLength(@Nullable String text, String message) { public static void hasLength(@Nullable String text, String message) {
if (!StringUtils.hasLength(text)) { if (!StringUtils.hasLength(text)) {
@ -238,14 +245,15 @@ 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.
* <pre class="code"> * <pre class="code">
* Assert.hasLength(name, () -&gt; "Name for account '" + account.getId() + "' must not be empty"); * Assert.hasLength(account.getName(),
* () -&gt; "Name for account '" + account.getId() + "' must not be empty");
* </pre> * </pre>
* @param text the String to check * @param text the String to check
* @param messageSupplier a supplier for the exception message to use if the * @param messageSupplier a supplier for the exception message to use if the
* assertion fails * assertion fails
* @see StringUtils#hasLength
* @throws IllegalArgumentException if the text is empty * @throws IllegalArgumentException if the text is empty
* @since 5.0 * @since 5.0
* @see StringUtils#hasLength
*/ */
public static void hasLength(@Nullable String text, Supplier<String> messageSupplier) { public static void hasLength(@Nullable String text, Supplier<String> messageSupplier) {
if (!StringUtils.hasLength(text)) { if (!StringUtils.hasLength(text)) {
@ -254,6 +262,8 @@ 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)}
*/ */
@Deprecated @Deprecated
@ -268,8 +278,8 @@ public abstract class Assert {
* <pre class="code">Assert.hasText(name, "'name' must not be empty");</pre> * <pre class="code">Assert.hasText(name, "'name' must not be empty");</pre>
* @param text the String to check * @param text the String to check
* @param message the exception message to use if the assertion fails * @param message the exception message to use if the assertion fails
* @see StringUtils#hasText
* @throws IllegalArgumentException if the text does not contain valid text content * @throws IllegalArgumentException if the text does not contain valid text content
* @see StringUtils#hasText
*/ */
public static void hasText(@Nullable String text, String message) { public static void hasText(@Nullable String text, String message) {
if (!StringUtils.hasText(text)) { if (!StringUtils.hasText(text)) {
@ -281,14 +291,15 @@ 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.
* <pre class="code"> * <pre class="code">
* Assert.hasText(name, () -&gt; "Name for account '" + account.getId() + "' must not be empty"); * Assert.hasText(account.getName(),
* () -&gt; "Name for account '" + account.getId() + "' must not be empty");
* </pre> * </pre>
* @param text the String to check * @param text the String to check
* @param messageSupplier a supplier for the exception message to use if the * @param messageSupplier a supplier for the exception message to use if the
* assertion fails * assertion fails
* @see StringUtils#hasText
* @throws IllegalArgumentException if the text does not contain valid text content * @throws IllegalArgumentException if the text does not contain valid text content
* @since 5.0 * @since 5.0
* @see StringUtils#hasText
*/ */
public static void hasText(@Nullable String text, Supplier<String> messageSupplier) { public static void hasText(@Nullable String text, Supplier<String> messageSupplier) {
if (!StringUtils.hasText(text)) { if (!StringUtils.hasText(text)) {
@ -297,6 +308,8 @@ 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)}
*/ */
@Deprecated @Deprecated
@ -340,6 +353,7 @@ 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)}
*/ */
@Deprecated @Deprecated
@ -381,6 +395,8 @@ 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)}
*/ */
@Deprecated @Deprecated
@ -429,6 +445,7 @@ 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)}
*/ */
@Deprecated @Deprecated
@ -471,6 +488,8 @@ 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)}
*/ */
@Deprecated @Deprecated
@ -512,6 +531,8 @@ 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)}
*/ */
@Deprecated @Deprecated

Loading…
Cancel
Save