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 936ec4660f6..bfda5b058e4 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-2017 the original author or authors. + * Copyright 2002-2020 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. @@ -80,8 +80,8 @@ public abstract class Assert { *
Call {@link #isTrue} if you wish to throw an {@code IllegalArgumentException} * on an assertion failure. *
- * Assert.state(id == null, - * () -> "ID for " + entity.getName() + " must not already be initialized"); + * Assert.state(entity.getId() == null, + * () -> "ID for entity " + entity.getName() + " must not already be initialized"); ** @param expression a boolean expression * @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 @@ -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 @@ -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 @@ -197,7 +202,8 @@ public abstract class Assert { /** * Assert that an object is not {@code null}. *
- * Assert.notNull(clazz, () -> "The class '" + clazz.getName() + "' must not be null"); + * Assert.notNull(entity.getId(), + * () -> "ID for entity " + entity.getName() + " must not be null"); ** @param object the object to check * @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 @@ -225,8 +232,8 @@ public abstract class Assert { *
Assert.hasLength(name, "Name must not be empty");* @param text the String to check * @param message the exception message to use if the assertion fails - * @see StringUtils#hasLength * @throws IllegalArgumentException if the text is empty + * @see StringUtils#hasLength */ public static void hasLength(@Nullable String text, String message) { if (!StringUtils.hasLength(text)) { @@ -238,14 +245,15 @@ 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. *
- * Assert.hasLength(name, () -> "Name for account '" + account.getId() + "' must not be empty"); + * Assert.hasLength(account.getName(), + * () -> "Name for account '" + account.getId() + "' must not be empty"); ** @param text the String to check * @param messageSupplier a supplier for the exception message to use if the * assertion fails - * @see StringUtils#hasLength * @throws IllegalArgumentException if the text is empty * @since 5.0 + * @see StringUtils#hasLength */ public static void hasLength(@Nullable String text, Supplier
Assert.hasText(name, "'name' must not be empty");* @param text the String to check * @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 + * @see StringUtils#hasText */ public static void hasText(@Nullable String text, String message) { 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 * be {@code null} and must contain at least one non-whitespace character. *
- * Assert.hasText(name, () -> "Name for account '" + account.getId() + "' must not be empty"); + * Assert.hasText(account.getName(), + * () -> "Name for account '" + account.getId() + "' must not be empty"); ** @param text the String to check * @param messageSupplier a supplier for the exception message to use if the * assertion fails - * @see StringUtils#hasText * @throws IllegalArgumentException if the text does not contain valid text content * @since 5.0 + * @see StringUtils#hasText */ public static void hasText(@Nullable String text, Supplier