jspecify / jspecify/jdk

`requireNonNull(..., Supplier<@Nullable String> messageSupplier`?

Open
#104 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
7
Forks
3
Avg merge
15h 17m
Merged PRs (30d)
8

Description

Currently, we require a supplier that returns a non-null string:

https://github.com/jspecify/jdk/blob/457b29286178d19b73503b54c2b09461409b6deb/src/java.base/share/classes/java/util/Objects.java#L357

However, the resulting string is merely passed as an exception message, so null would be fine as a result.

The somewhat unfortunate thing is that the Java base type forces us to choose between Supplier<String> and Supplier<@Nullable String>, at least in the absence of @PolyNull. (What we'd prefer is a base type of Supplier<? extends String>, which we could then annotate as Supplier<? extends @Nullable String>.)

It's also a little sad that "Supplier<@Nullable String>" just looks more complicated in general. But then probably few people actually look at the stubs directly.

We could try Supplier<@Nullable String> and see if there's any fallout from callers who pass an explicit Supplier<@Nullable String>. My guess is that callers are using lambdas over anonymous classes, so they won't generally specify explicit types. But we might see cases in which people have declared their own APIs with Supplier<String>, in which case this change would break them, requiring them to change their own APIs or pass supplier::get as a way of translating (and setting off static analysis like https://errorprone.info/bugpattern/UnnecessaryMethodReference... :). I'll see what the Google results look like. If I see a lot of errors, I'm not sure if my conclusion will be "not worth the trouble" or "better fix this now before it gets harder"....

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/java.base/share/classes/java/util/Objects.java at the linked requireNonNull overload and review the Supplier type annotation. Search for callers that explicitly declare Supplier or Supplier<@Nullable String>, then assess the compatibility fallout described in the issue. Done means reaching and documenting a decision on the nullable annotation change.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.