Skip to content

Commit 62fef5a

Browse files
committed
Fix example in Javadoc for Assert.notNull(object, messageSupplier)
Closes gh-25774
1 parent 592f3f8 commit 62fef5a

File tree

1 file changed

+31
-10
lines changed
  • spring-core/src/main/java/org/springframework/util

1 file changed

+31
-10
lines changed

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

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -80,8 +80,8 @@ public static void state(boolean expression, String message) {
8080
* <p>Call {@link #isTrue} if you wish to throw an {@code IllegalArgumentException}
8181
* on an assertion failure.
8282
* <pre class="code">
83-
* Assert.state(id == null,
84-
* () -&gt; "ID for " + entity.getName() + " must not already be initialized");
83+
* Assert.state(entity.getId() == null,
84+
* () -&gt; "ID for entity " + entity.getName() + " must not already be initialized");
8585
* </pre>
8686
* @param expression a boolean expression
8787
* @param messageSupplier a supplier for the exception message to use if the
@@ -96,6 +96,8 @@ public static void state(boolean expression, Supplier<String> messageSupplier) {
9696
}
9797

9898
/**
99+
* Assert a boolean expression, throwing an {@code IllegalStateException}
100+
* if the expression evaluates to {@code false}.
99101
* @deprecated as of 4.3.7, in favor of {@link #state(boolean, String)}
100102
*/
101103
@Deprecated
@@ -136,6 +138,8 @@ public static void isTrue(boolean expression, Supplier<String> messageSupplier)
136138
}
137139

138140
/**
141+
* Assert a boolean expression, throwing an {@code IllegalArgumentException}
142+
* if the expression evaluates to {@code false}.
139143
* @deprecated as of 4.3.7, in favor of {@link #isTrue(boolean, String)}
140144
*/
141145
@Deprecated
@@ -174,6 +178,7 @@ public static void isNull(@Nullable Object object, Supplier<String> messageSuppl
174178
}
175179

176180
/**
181+
* Assert that an object is {@code null}.
177182
* @deprecated as of 4.3.7, in favor of {@link #isNull(Object, String)}
178183
*/
179184
@Deprecated
@@ -197,7 +202,8 @@ public static void notNull(@Nullable Object object, String message) {
197202
/**
198203
* Assert that an object is not {@code null}.
199204
* <pre class="code">
200-
* Assert.notNull(clazz, () -&gt; "The class '" + clazz.getName() + "' must not be null");
205+
* Assert.notNull(entity.getId(),
206+
* () -&gt; "ID for entity " + entity.getName() + " must not be null");
201207
* </pre>
202208
* @param object the object to check
203209
* @param messageSupplier a supplier for the exception message to use if the
@@ -212,6 +218,7 @@ public static void notNull(@Nullable Object object, Supplier<String> messageSupp
212218
}
213219

214220
/**
221+
* Assert that an object is not {@code null}.
215222
* @deprecated as of 4.3.7, in favor of {@link #notNull(Object, String)}
216223
*/
217224
@Deprecated
@@ -225,8 +232,8 @@ public static void notNull(@Nullable Object object) {
225232
* <pre class="code">Assert.hasLength(name, "Name must not be empty");</pre>
226233
* @param text the String to check
227234
* @param message the exception message to use if the assertion fails
228-
* @see StringUtils#hasLength
229235
* @throws IllegalArgumentException if the text is empty
236+
* @see StringUtils#hasLength
230237
*/
231238
public static void hasLength(@Nullable String text, String message) {
232239
if (!StringUtils.hasLength(text)) {
@@ -238,14 +245,15 @@ public static void hasLength(@Nullable String text, String message) {
238245
* Assert that the given String is not empty; that is,
239246
* it must not be {@code null} and not the empty String.
240247
* <pre class="code">
241-
* Assert.hasLength(name, () -&gt; "Name for account '" + account.getId() + "' must not be empty");
248+
* Assert.hasLength(account.getName(),
249+
* () -&gt; "Name for account '" + account.getId() + "' must not be empty");
242250
* </pre>
243251
* @param text the String to check
244252
* @param messageSupplier a supplier for the exception message to use if the
245253
* assertion fails
246-
* @see StringUtils#hasLength
247254
* @throws IllegalArgumentException if the text is empty
248255
* @since 5.0
256+
* @see StringUtils#hasLength
249257
*/
250258
public static void hasLength(@Nullable String text, Supplier<String> messageSupplier) {
251259
if (!StringUtils.hasLength(text)) {
@@ -254,6 +262,8 @@ public static void hasLength(@Nullable String text, Supplier<String> messageSupp
254262
}
255263

256264
/**
265+
* Assert that the given String is not empty; that is,
266+
* it must not be {@code null} and not the empty String.
257267
* @deprecated as of 4.3.7, in favor of {@link #hasLength(String, String)}
258268
*/
259269
@Deprecated
@@ -268,8 +278,8 @@ public static void hasLength(@Nullable String text) {
268278
* <pre class="code">Assert.hasText(name, "'name' must not be empty");</pre>
269279
* @param text the String to check
270280
* @param message the exception message to use if the assertion fails
271-
* @see StringUtils#hasText
272281
* @throws IllegalArgumentException if the text does not contain valid text content
282+
* @see StringUtils#hasText
273283
*/
274284
public static void hasText(@Nullable String text, String message) {
275285
if (!StringUtils.hasText(text)) {
@@ -281,14 +291,15 @@ public static void hasText(@Nullable String text, String message) {
281291
* Assert that the given String contains valid text content; that is, it must not
282292
* be {@code null} and must contain at least one non-whitespace character.
283293
* <pre class="code">
284-
* Assert.hasText(name, () -&gt; "Name for account '" + account.getId() + "' must not be empty");
294+
* Assert.hasText(account.getName(),
295+
* () -&gt; "Name for account '" + account.getId() + "' must not be empty");
285296
* </pre>
286297
* @param text the String to check
287298
* @param messageSupplier a supplier for the exception message to use if the
288299
* assertion fails
289-
* @see StringUtils#hasText
290300
* @throws IllegalArgumentException if the text does not contain valid text content
291301
* @since 5.0
302+
* @see StringUtils#hasText
292303
*/
293304
public static void hasText(@Nullable String text, Supplier<String> messageSupplier) {
294305
if (!StringUtils.hasText(text)) {
@@ -297,6 +308,8 @@ public static void hasText(@Nullable String text, Supplier<String> messageSuppli
297308
}
298309

299310
/**
311+
* Assert that the given String contains valid text content; that is, it must not
312+
* be {@code null} and must contain at least one non-whitespace character.
300313
* @deprecated as of 4.3.7, in favor of {@link #hasText(String, String)}
301314
*/
302315
@Deprecated
@@ -340,6 +353,7 @@ public static void doesNotContain(@Nullable String textToSearch, String substrin
340353
}
341354

342355
/**
356+
* Assert that the given text does not contain the given substring.
343357
* @deprecated as of 4.3.7, in favor of {@link #doesNotContain(String, String, String)}
344358
*/
345359
@Deprecated
@@ -381,6 +395,8 @@ public static void notEmpty(@Nullable Object[] array, Supplier<String> messageSu
381395
}
382396

383397
/**
398+
* Assert that an array contains elements; that is, it must not be
399+
* {@code null} and must contain at least one element.
384400
* @deprecated as of 4.3.7, in favor of {@link #notEmpty(Object[], String)}
385401
*/
386402
@Deprecated
@@ -429,6 +445,7 @@ public static void noNullElements(@Nullable Object[] array, Supplier<String> mes
429445
}
430446

431447
/**
448+
* Assert that an array contains no {@code null} elements.
432449
* @deprecated as of 4.3.7, in favor of {@link #noNullElements(Object[], String)}
433450
*/
434451
@Deprecated
@@ -471,6 +488,8 @@ public static void notEmpty(@Nullable Collection<?> collection, Supplier<String>
471488
}
472489

473490
/**
491+
* Assert that a collection contains elements; that is, it must not be
492+
* {@code null} and must contain at least one element.
474493
* @deprecated as of 4.3.7, in favor of {@link #notEmpty(Collection, String)}
475494
*/
476495
@Deprecated
@@ -512,6 +531,8 @@ public static void notEmpty(@Nullable Map<?, ?> map, Supplier<String> messageSup
512531
}
513532

514533
/**
534+
* Assert that a Map contains entries; that is, it must not be {@code null}
535+
* and must contain at least one entry.
515536
* @deprecated as of 4.3.7, in favor of {@link #notEmpty(Map, String)}
516537
*/
517538
@Deprecated

0 commit comments

Comments
 (0)