Current javadoc of Assert.notNull(object, messageSupplier) methods contains an example:
Assert.notNull(clazz, () -> "The class '" + clazz.getName() + "' must not be null");
|
/** |
|
* Assert that an object is not {@code null}. |
|
* <pre class="code"> |
|
* Assert.notNull(clazz, () -> "The class '" + clazz.getName() + "' must not be null"); |
|
* </pre> |
|
* @param object the object to check |
|
* @param messageSupplier a supplier for the exception message to use if the |
|
* assertion fails |
|
* @throws IllegalArgumentException if the object is {@code null} |
|
* @since 5.0 |
|
*/ |
|
public static void notNull(@Nullable Object object, Supplier<String> messageSupplier) { |
|
if (object == null) { |
|
throw new IllegalArgumentException(nullSafeGet(messageSupplier)); |
|
} |
|
} |
This example is incorrect because it will lead to NPE in the messageSupplier.get(), that will be called if clazz is null.
I can create a PR to fix this, but I'm unsure what simple and descriptive example can show the intention of this variant of the method.
Whatever comes to my mind contains another object, that will be used in the message (not the object under assertion).
Like:
Object someObj = getSomeObj();
Assert.notNull(clazz, () -> "Some message that involves '" + someObj.someMethod());
If there is not someObj in the equation, then why we need a Supplier in the first place?
But this is obviously not a good example. Too broad.
But javadoc need to be fixed anyway. It is just confusing now.
Current javadoc of
Assert.notNull(object, messageSupplier)methods contains an example:spring-framework/spring-core/src/main/java/org/springframework/util/Assert.java
Lines 205 to 220 in fe9f29f
This example is incorrect because it will lead to NPE in the
messageSupplier.get(), that will be called ifclazzis null.I can create a PR to fix this, but I'm unsure what simple and descriptive example can show the intention of this variant of the method.
Whatever comes to my mind contains another object, that will be used in the message (not the object under assertion).
Like:
If there is not
someObjin the equation, then why we need aSupplierin the first place?But this is obviously not a good example. Too broad.
But javadoc need to be fixed anyway. It is just confusing now.