Skip to content

Commit

Permalink
Allow messageSupplier to be null.
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.)
  • Loading branch information
cpovirk committed Nov 6, 2024
1 parent 457b292 commit 9af7027
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 @@ -354,7 +354,7 @@ public static <T> T requireNonNullElseGet(@Nullable T obj, Supplier<? extends @N
*/


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 9af7027

Please sign in to comment.