-
Notifications
You must be signed in to change notification settings - Fork 31
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
Annotate much of java.time for nullness. #72
base: master
Are you sure you want to change the base?
Conversation
@@ -96,6 +98,7 @@ | |||
* | |||
* @since 1.8 | |||
*/ | |||
@AnnotatedFor({"nullness"}) | |||
public interface TemporalAmount { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs for get
and getUnits
are not explicit about whether their TemporalUnit
instances can be null.
Both JDK implementation of TemporalAmount
reject nulls from get
(Period
, Duration
) -- albeit by throwing UnsupportedTemporalTypeException
instead of NullPointerException
. This means that we need to omit @Nullable
here if we want to be safe.
For getUnits
, the TemporalUnit
instances are an output, so we could in principle still have @Nullable
there. But java.time
is consistent in treating a null TemporalUnit
as bogus: See, for example, Temporal.isSupported
, or see the use of similar TemporalField
in TemporalAccessor.get
. That probably argues for doing the same here. (Alternatively, it argues that this one exception could have been intentional :) But I think that would be at least a little perverse.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for these annotations. They are a useful addition. I have one concern.
Method TemporalQuery.queryFrom
is documented as possibly returning null, but its return type is R
and R
might be instantiated as a non-null type. This seems wrong to me. I have the same concern about TemporalAccessor.query
and its overrides. Am I missing something?
I found the docs around
And when I say "callers of Ah, but as I am writing this, I see the following on
So I believe that we have justification to conclude that I've added a |
No description provided.