-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
requireNonNull(..., Supplier<@Nullable String> messageSupplier
?
#104
Comments
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.)
The change works fine in the Google depot. |
Do you see any code that is incorrect when using |
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]>
I'm not aware of any trouble from the |
Currently, we require a supplier that returns a non-null string:
jdk/src/java.base/share/classes/java/util/Objects.java
Line 357 in 457b292
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>
andSupplier<@Nullable String>
, at least in the absence of@PolyNull
. (What we'd prefer is a base type ofSupplier<? extends String>
, which we could then annotate asSupplier<? 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 explicitSupplier<@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 withSupplier<String>
, in which case this change would break them, requiring them to change their own APIs or passsupplier::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"....The text was updated successfully, but these errors were encountered: