Skip to content

Commit

Permalink
Allow messageSupplier to be null. (#105)
Browse files Browse the repository at this point in the history
The docs at best indirectly imply that it can be `null`: They have a
`@throws NullPointerException` clause that mentions only the case in
which `obj` is `null`, without saying anything similar about
`messageSupplier`.

But of course I'm actually going mostly off the implementation....

(Note that this PR is separate from
#104, which describes *another*
change that we could make to this parameter.)

Co-authored-by: Werner Dietl <[email protected]>
  • Loading branch information
cpovirk and wmdietl authored Dec 18, 2024
1 parent c9befbc commit f669c5b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/util/Objects.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public static <T> T requireNonNullElseGet(@Nullable T obj, Supplier<? extends @N
* @throws NullPointerException if {@code obj} is {@code null}
* @since 1.8
*/
public static <T> T requireNonNull(@Nullable T obj, Supplier<String> messageSupplier) {
public static <T> T requireNonNull(@Nullable T obj, @Nullable Supplier<String> messageSupplier) {
if (obj == null)
throw new NullPointerException(messageSupplier == null ?
null : messageSupplier.get());
Expand Down

0 comments on commit f669c5b

Please sign in to comment.