Current javadoc of Assert.notNull(object, messageSupplier) methods contains an example:

Assert.notNull(clazz, () -> "The class '" + clazz.getName() + "' must not be null");

https://github.com/spring-projects/spring-framework/blob/fe9f29f03148ee0a28019a7f3322a126d2bced30/spring-core/src/main/java/org/springframework/util/Assert.java#L205-L220

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.

Comment From: sbrannen

Good catch!

And well... I apologize for introducing that invalid example (in https://github.com/spring-projects/spring-framework/commit/17dd5dd22d9b68bf60c302833c8c33d3cb914ed3#diff-63b82daba31953240dc1385e17c3e2b6R143).

We'll come up with a meaningful (non-broken) example. 😉

Comment From: sbrannen

Whatever comes to my mind contains another object, that will be used in the message (not the object under assertion).

I ended up fixing the example by aligning it with other similar examples in https://github.com/spring-projects/spring-framework/commit/a6daed1b71ae15dc6175a895810ce4fb0045b865.