You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I propose we use the word "unknown" with greatest care and use more specific terms wherever possible.
Any concrete type without a nullness annotation (explicit or from default) is "unspecified", or has "unspecified nullness".
A type parameter with no nullness specification for its bounds is "unconstrained", or has "unconstrained nullness". The same for wildcards.
A local variable that will hold null if one branch in the code is taken, and nonnull on others, also has unknown nullness, but here the reason is closely connected to local flow analysis.
While (3) is mostly irrelevant for our task (but relevant for warnings issued by checkers), I believe the difference between (1) and (2) is key for getting a convincing story for type parameters / type variables / wildcards.
Avoiding (1) is necessary for soundiness, because practically checkers cannot check against unspecified signatures. Unspecified closely relates to "unchecked".
Avoiding (2) is not necessary at all, if instantiation of such generic types still ensures that all type arguments have specified nullness.
A type parameter with no nullness specification for its bounds is "unconstrained", or has "unconstrained nullness". The same for wildcards.
...
Avoiding (2) is not necessary [for soundness], if instantiation of such generic types still ensures that all type arguments have specified nullness.
Duplicating myself from #45, I'm seeing this differently (or just misunderstanding you):
Suppose that the T in Optional<T> has "unconstrained nullness" (presumably because we don't have a stub defined for it, even though in practice we would). Then suppose that a user tries to create an Optional<@Nullable String> with Optional.of(null). The user is specifying a nullness value for the type argument, but the call is still unsound.
The "pessimistic checking" you describe sounds to me like it has the same goal as the spec here has. The spec does it by:
treating unannotated type parameters as having an @UnknownNullness bound
applying the unknown nullness to all usage sites (unless explicitly annotated), regardless of the instantiated type
The spec would (as I understand it) produce warnings in both the example cases you give. Unless that's wishful thinking on my part?
This term refers to checking bodies of a generic class. So if requireNonNull() were annotated as requireNonNull(@NonNull T obj) then pessimistic analysis would report that this constructor:
is bogus because it passes a value of type T (which could be a nullable type) where requireNonNull requires a nonnull value. So to fix this class we'd need to add a bound to the type parameter, such as to constrain T to only nonnull types. After that fix, the instantiation Optional<@Nullable String> will be detected as bogus. Voila.
Issues involving an unconstrained type parameter are a different kind of issue than any "null-unchecked" conversion. The latter only happens when "legacy" code is involved, whereas an unconstrained type parameter is perfectly OK also in 100% annotated code. I hold that ability to separately configure severity for both kinds of warnings is important.
Thanks. Is the ability to separately configure severity the main enhancement desired? Are there other enhancements that you can tell I've missed?
Configurable severity reminds me of #55, which I know you've seen.
I suspect that "pessimistic checking," which sounds like "parametric nullability" under Discussion: Expression Types, will have a distinct warning type from the legacy/unspecified case. I base that on discussions like #57 (comment) and #33 (comment), which differentiate between "strict" and "lenient" modes based on whether "unchecked" conversions (those involving legacy/unspecified warnings) are errors.
If we're lucky, the needed distinctions might already exist. But again, I may be missing other parts to this.
I think I'm in 100% agreement with Stephan on the concepts, and we'll just have to pull our terminology together sometime soon.
The third kind of nullness, which (non-primitive, etc.) legacy type usages have by default, is probably best described as "unspecified nullness". (This is the case we started trying to consistently call "unknown nullness" a month or two ago, but I'm more than open to a shift.)
On the other hand, for a bounded type variable:
If the upper bound is @NotNull (whether explicitly or because we decided defaults apply here -- that part debated elsewhere), we simply say the unannotated type variable usages are also definitively @NotNull, because why not.
If the upper bound is @nullable (same parenthetical as above), we have been saying that unannotated type variable usages have "parametric nullness", though "unconstrained nullness" sounds like a good fit for this too. And this is definitely different from unspecified nullness (even the JVMLS slides make a quick mention of this); I think trying to assign something nullable to it, or assign it to something non-nullable, is more a of "hard no" than just an "unchecked-ish warning".
If the upper bound is of unspecified nullness (perhaps explicitly, but usually because no default exists), I think we need to flesh out this story better. The conceptualization in How to conceptualize subtyping for legacy-nullness #33 (notnull <: unspec <: nullable) would imply that it can be parameterized with either unspec or notnull but not with nullable, but I haven't yet figured out whether that asymmetry is sensible or a weird accident. There should be an issue somewhere that's about that, but I'm not spotting it easily atm. [cpovirk edits: Some of this is under discussion in what happens to type variables when @NullnessUnknown (and @NotNull) type parameters are instantiated? #45.]
I think we were all in sync on the conceptual model put forth here, and basically still are.
Just in terms of actual word choices -- I might kinda like "unconstrained" over "parametric" because it more clearly works well for both type variables and wildcards. This may be a term we just need for conversational purposes, though. Officially the stance could be that these (like intersection types) don't have any describable nullness of their own.
(I just couldn't quite rationalize keeping this whole issue open, over the unconstrained-vs.-parametric word choice alone. But you can still comment while it's closed if you want to share any opinion.,
Activity
cpovirk commentedon Aug 12, 2019
Duplicating myself from #45, I'm seeing this differently (or just misunderstanding you):
Suppose that the
TinOptional<T>has "unconstrained nullness" (presumably because we don't have a stub defined for it, even though in practice we would). Then suppose that a user tries to create anOptional<@Nullable String>withOptional.of(null). The user is specifying a nullness value for the type argument, but the call is still unsound.The "pessimistic checking" you describe sounds to me like it has the same goal as the spec here has. The spec does it by:
@UnknownNullnessboundThe spec would (as I understand it) produce warnings in both the example cases you give. Unless that's wishful thinking on my part?
stephan-herrmann commentedon Aug 12, 2019
This term refers to checking bodies of a generic class. So if
requireNonNull()were annotated asrequireNonNull(@NonNull T obj)then pessimistic analysis would report that this constructor:is bogus because it passes a value of type
T(which could be a nullable type) whererequireNonNullrequires a nonnull value. So to fix this class we'd need to add a bound to the type parameter, such as to constrainTto only nonnull types. After that fix, the instantiationOptional<@Nullable String>will be detected as bogus. Voila.Issues involving an unconstrained type parameter are a different kind of issue than any "null-unchecked" conversion. The latter only happens when "legacy" code is involved, whereas an unconstrained type parameter is perfectly OK also in 100% annotated code. I hold that ability to separately configure severity for both kinds of warnings is important.
cpovirk commentedon Aug 12, 2019
Thanks. Is the ability to separately configure severity the main enhancement desired? Are there other enhancements that you can tell I've missed?
Configurable severity reminds me of #55, which I know you've seen.
I suspect that "pessimistic checking," which sounds like "parametric nullability" under Discussion: Expression Types, will have a distinct warning type from the legacy/unspecified case. I base that on discussions like #57 (comment) and #33 (comment), which differentiate between "strict" and "lenient" modes based on whether "unchecked" conversions (those involving legacy/unspecified warnings) are errors.
If we're lucky, the needed distinctions might already exist. But again, I may be missing other parts to this.
kevinb9n commentedon Aug 14, 2019
I think I'm in 100% agreement with Stephan on the concepts, and we'll just have to pull our terminology together sometime soon.
The third kind of nullness, which (non-primitive, etc.) legacy type usages have by default, is probably best described as "unspecified nullness". (This is the case we started trying to consistently call "unknown nullness" a month or two ago, but I'm more than open to a shift.)
On the other hand, for a bounded type variable:
If the upper bound is @NotNull (whether explicitly or because we decided defaults apply here -- that part debated elsewhere), we simply say the unannotated type variable usages are also definitively @NotNull, because why not.
If the upper bound is @nullable (same parenthetical as above), we have been saying that unannotated type variable usages have "parametric nullness", though "unconstrained nullness" sounds like a good fit for this too. And this is definitely different from unspecified nullness (even the JVMLS slides make a quick mention of this); I think trying to assign something nullable to it, or assign it to something non-nullable, is more a of "hard no" than just an "unchecked-ish warning".
If the upper bound is of unspecified nullness (perhaps explicitly, but usually because no default exists), I think we need to flesh out this story better. The conceptualization in How to conceptualize subtyping for legacy-nullness #33 (notnull <: unspec <: nullable) would imply that it can be parameterized with either unspec or notnull but not with nullable, but I haven't yet figured out whether that asymmetry is sensible or a weird accident. There should be an issue somewhere that's about that, but I'm not spotting it easily atm. [cpovirk edits: Some of this is under discussion in what happens to type variables when @NullnessUnknown (and @NotNull) type parameters are instantiated? #45.]
kevinb9n commentedon Jun 19, 2021
I think we were all in sync on the conceptual model put forth here, and basically still are.
Just in terms of actual word choices -- I might kinda like "unconstrained" over "parametric" because it more clearly works well for both type variables and wildcards. This may be a term we just need for conversational purposes, though. Officially the stance could be that these (like intersection types) don't have any describable nullness of their own.
kevinb9n commentedon Jun 19, 2021
(I just couldn't quite rationalize keeping this whole issue open, over the unconstrained-vs.-parametric word choice alone. But you can still comment while it's closed if you want to share any opinion.,