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
{{ message }}
Repository navigation
Applicability of TYPE_USE annotations to class declarations #7
TYPE_USE allows annotations to appear on a class declaration.
This is useful to specify classes that should not be allowed to be @Nullable, for example, java.util.Optional should never be used as @Nullable Optional.
This can be achieved with the following declaration:
@NotNullclassOptional<T> {...}
If nothing is specified, all class declarations are @Nullable, allowing @Nullable uses. Explicit uses of @Nullable should be forbidden.
This goes well together with @NotNullByDefault, as e.g. parameter types are @NotNull by default. With @NullableByDefault and the above Optional declaration, all uses of Optional would need to be annotated @NotNull explicitly.
Should we define this semantic or keep this for a future extension?
Do we think class declaration annotations are useful for anyone to enforce this property?
Do we agree that we should use this for java.util.Optional? That is, are you a believer in @kevinb9n Optional rules or in Stuart Mark's.
Question 2 raises a more general issue: are we imagining standard CodeAnalysis specifications for the JDK? Eclipse, the Checker Framework, and other tools come with JDK specifications. Are we imagining a repository with agreed upon specifications?
I don't think there is any such thing as a class that should viewed as "never let this be nullable". As soon as you try to get that thing out of a Map, there you are.
I claim it does not make sense for a class to try to constrain what kinds of nullability its type usages can have. The Map.get just mentioned example illustrates that nullability often has nothing to do with the specific type in question.
So, I believe our type-use annotations should all be disallowed to appear as type annotations.
(There is also the chance that they could be misconstrued as setting the default nullability for elements contained in the class.)
I will acknowledge that Optional, collections, and enums that define an "unknown" constant are examples of cases where you might want to discourage nullable usages of their static type.
My leaning right now is that even if we want to assist in that kind of check, public class @NotNull Foo is not self-evident enough in its meaning. (One issue already mentioned is that it might be assumed to function like @DefaultNotNull.)
So I am still content to consider this closed for now.
Another use case might be marking Void as always@Nullable, but I can't think of any other class that should ever do that (an empty enum? but pray tell why?), so it doesn't amount to a strong argument imho.
Meta-annotations are indeed a common patterns in Spring, and an alternative to the @Implies feature could simply be to allow meta-annotating custom annotation classes definition with JSpecify annotations, and treat those custom annotations as aliases. So I am wondering if that could make sense to authorize (in the spec) such usage only on other annotation classes definitions. See also this related comment.
I would like to discuss if all usages on class declaration should be forbidden in the spec in 1.0, and potentially authorized post 1.0 (for example 1.1). But I have related fears that if we forbid that now, that will be a nightmare if we introduce that later with some tools supporting it and some other triggering an error. As consequence, I thumbs-down this issue in order to have a related discussion before taking a decision.
For other use cases than annotation classe declarations, I am ok to consider them not legal.
If it's okay, I'll file a separate issue about the implies use case. The possible resolutions for that issue would be "we provide @Implies", "we support meta-annotation" -- or, of course, if it's deprioritized or closed, then "neither".
Then, this issue would cover whether our annotations would be allowed on class declarations for any other purpose but that. (The thread above covers the common use case we were aware of, but there could be others.) This part might be easy to get consensus on.
Then, this issue would cover whether our annotations would be allowed on class declarations for any other purpose but that. (The thread above covers the common use case we were aware of, but there could be others.) This part might be easy to get consensus on.
Ok for that, once clarified I will turn my thumbs down to thumbs up.
If it's okay, I'll file a separate issue about the implies use case.
I would maybe suggest waiting we discuss the document I am about to write before creating a new issue if that's ok for you.
For this issue, I'll change the wording of the proposal to this:
Proposal: JSpecify 1.0 will not allow its type-use annotations (@Nullable and @NonNull) to apply to general class declarations. However, these annotations applied to annotation types are considered meaningless but reserved for future use. The annotation in @Nullable class Foo {} is meaningless, as is the one in @Nullable @interface Bar {}, but the latter may become meaningful in a future version of JSpecify.
Note that this doesn't represent a significant change to the previous proposal (#7 (comment)) in that that proposal also considers these annotations to be meaningless on annotation types, but it does clarify that we may assign a meaning to such annotations in the future, whereas we plan not to assign any meaning to them on other class types.
If you agree, please add a thumbs-up emoji (👍) to this comment. If you disagree, please add a thumbs-down emoji (👎) to this comment and briefly explain your disagreement. Please only add a thumbs-down if you feel you can make a strong case why this decision will be materially worse for users or tool providers than an alternative. Note: A thumbs-up on the previous proposal will be considered a thumbs-up to this proposal as well.
❗EDIT on 2024-05-21: Please see the new proposal below (#7 (comment)).
I'm not adding a thumbs-down, as a mere bystander I'm sure I don't fully understand the reasoning behind this, but ..
@nullable class Foo {} is not legal, but @nullable interface Bar {} is [legal] meaningless ...
I can't help but feel that this breaks the principle of least surprise, no? One is legal, the other is not.
Also, what about an interface that has default method? What will the implication be on those default methods? Why is that different from standard class methods?
@Nullable class Foo {} is not legal, but @Nullable interface Bar {} is [legal] meaningless ...
To clarify:
We're talking about annotation types, so your second example should be @Nullable @interface Bar {}. As you say, interfaces and classes are pretty similar and it would be surprising for JSpecify to treat them differently; but annotation types are very different from both, and so it's not so surprising if JSpecify treated them differently.
The difference between "not legal" and "meaningless" is a fine one, and maybe "not legal" is a bad phrase. (I'll edit the revised proposal to remove "not legal".) The clarification I'm trying to make here is that although the annotations in @Nullable class Foo {} and @Nullable @interface Bar {} are both meaningless in JSpecify 1.0, the latter may have some meaning in a future version of JSpecify.
JSpecify 1.0 will not allow its type-use annotations (@Nullable and @NonNull) to apply to general class declarations.
I'm not sure what a "general class declaration" is, but here the annotations are "not allowed".
Then later: The annotation in @Nullable class Foo {} is meaningless, as is the one in @Nullable @interface Bar {}, but the latter may become meaningful in a future version of JSpecify.
Here the proposal uses "meaningless" for both cases.
So are the annotations "not allowed" or "meaningless"?
Have we ever put anything else in this category "meaningless but reserved"? If not, I would much rather not casually start down that road. I would like putting a nullness annotation on a class declaration to be forever meaningless, because whatever meaning we might like it to have in the future, we would do better to define a new annotation to express that more clearly anyway. We can get into why, but not here/now.
My perspective would be that we need to make a decision for 1.0, and the only decision we can make for 1.0 is between "This is applicable with meaning x" and "This is not applicable." Any discussion of what might happen in the future is out of scope. In that respect, I'd see this issue as the same as all the other 1.0 issues, and I wouldn't try to differentiate is as "reserved," nor would I attempt to commit now to never using it. Neither strikes me as necessary: Those two options are exactly the options that we leave open by saying that the annotation is inapplicable for 1.0. And part of our goal is to avoid having to block 1.0 on even the basic shape of the design of an implication/aliasing system.
Proposal: JSpecify will not allow its type-use annotations (@Nullable and @NonNull) to apply to class (and interface, and annotation, etc.) declarations.
This proposal does not mean that JSpecify won't implement a mechanism for one annotation to imply another in the future (#35 and friends).
If you agree, please add a thumbs-up emoji (👍) to this comment. If you disagree, please add a thumbs-down emoji (👎) to this comment and briefly explain your disagreement. Please only add a thumbs-down if you feel you can make a strong case why this decision will be materially worse for users or tool providers than an alternative. Note: A thumbs-up on the original proposal will be considered a thumbs-up to this proposal as well.
Results: Five 👍 (including the two people with 👎 and 👀 on the original proposal), no other votemojis.
Reacted by Chris Povirk, Riley Park, Werner Dietl, Sébastien Deleuze and Kevin Bourrillion
Decision: JSpecify will not allow its type-use annotations (@Nullable and @NonNull) to apply to class (and interface, and annotation, etc.) declarations.
changed the title [-]Applicability of TYPE_USE annotations to class declarations [working decision: no][/-][+]Applicability of TYPE_USE annotations to class declarations[/+]on Jun 13, 2024
Activity
dzharkov commentedon Nov 26, 2018
Comments from the document:
kevinb9n commentedon Nov 26, 2018
Agree with Andrey.
kevin1e100 commentedon Dec 20, 2018
So noted
wmdietlGC commentedon Jan 10, 2019
TYPE_USE allows annotations to appear on a class declaration.
This is useful to specify classes that should not be allowed to be
@Nullable, for example,java.util.Optionalshould never be used as@Nullable Optional.This can be achieved with the following declaration:
If nothing is specified, all class declarations are
@Nullable, allowing@Nullableuses. Explicit uses of@Nullableshould be forbidden.This goes well together with
@NotNullByDefault, as e.g. parameter types are@NotNullby default. With@NullableByDefaultand the above Optional declaration, all uses of Optional would need to be annotated@NotNullexplicitly.Should we define this semantic or keep this for a future extension?
cushon commentedon Jan 10, 2019
I don't think there's consensus on that: https://stackoverflow.com/questions/9561295/whats-the-point-of-guavas-optional-class#comment12143090_9561334
wmdietlGC commentedon Jan 10, 2019
I think there are two questions:
java.util.Optional? That is, are you a believer in @kevinb9n Optional rules or in Stuart Mark's.Question 2 raises a more general issue: are we imagining standard CodeAnalysis specifications for the JDK? Eclipse, the Checker Framework, and other tools come with JDK specifications. Are we imagining a repository with agreed upon specifications?
kevin1e100 commentedon Jan 10, 2019
kevinb9n commentedon Apr 19, 2019
I don't think there is any such thing as a class that should viewed as "never let this be nullable". As soon as you try to get that thing out of a Map, there you are.
kevinb9n commentedon Jun 12, 2019
I claim it does not make sense for a class to try to constrain what kinds of nullability its type usages can have. The
Map.getjust mentioned example illustrates that nullability often has nothing to do with the specific type in question.So, I believe our type-use annotations should all be disallowed to appear as type annotations.
(There is also the chance that they could be misconstrued as setting the default nullability for elements contained in the class.)
kevinb9n commentedon Jun 26, 2019
I will acknowledge that Optional, collections, and enums that define an "unknown" constant are examples of cases where you might want to discourage nullable usages of their static type.
My leaning right now is that even if we want to assist in that kind of check,
public class @NotNull Foois not self-evident enough in its meaning. (One issue already mentioned is that it might be assumed to function like @DefaultNotNull.)So I am still content to consider this closed for now.
kevinb9n commentedon Jul 25, 2019
Another use case might be marking
Voidas always@Nullable, but I can't think of any other class that should ever do that (an empty enum? but pray tell why?), so it doesn't amount to a strong argument imho.7 remaining items
sdeleuze commentedon Apr 10, 2024
Meta-annotations are indeed a common patterns in Spring, and an alternative to the
@Impliesfeature could simply be to allow meta-annotating custom annotation classes definition with JSpecify annotations, and treat those custom annotations as aliases. So I am wondering if that could make sense to authorize (in the spec) such usage only on other annotation classes definitions. See also this related comment.I would like to discuss if all usages on class declaration should be forbidden in the spec in 1.0, and potentially authorized post 1.0 (for example 1.1). But I have related fears that if we forbid that now, that will be a nightmare if we introduce that later with some tools supporting it and some other triggering an error. As consequence, I thumbs-down this issue in order to have a related discussion before taking a decision.
For other use cases than annotation classe declarations, I am ok to consider them not legal.
kevinb9n commentedon Apr 10, 2024
If it's okay, I'll file a separate issue about the implies use case. The possible resolutions for that issue would be "we provide
@Implies", "we support meta-annotation" -- or, of course, if it's deprioritized or closed, then "neither".Then, this issue would cover whether our annotations would be allowed on class declarations for any other purpose but that. (The thread above covers the common use case we were aware of, but there could be others.) This part might be easy to get consensus on.
Sound okay?
[If not we at least need to reopen this issue]
sdeleuze commentedon Apr 10, 2024
Ok for that, once clarified I will turn my thumbs down to thumbs up.
I would maybe suggest waiting we discuss the document I am about to write before creating a new issue if that's ok for you.
netdpb commentedon May 7, 2024
For this issue, I'll change the wording of the proposal to this:
Proposal: JSpecify 1.0 will not allow its type-use annotations (
@Nullableand@NonNull) to apply to general class declarations. However, these annotations applied to annotation types are considered meaningless but reserved for future use. The annotation in@Nullable class Foo {}is meaningless, as is the one in@Nullable @interface Bar {}, but the latter may become meaningful in a future version of JSpecify.Note that this doesn't represent a significant change to the previous proposal (#7 (comment)) in that that proposal also considers these annotations to be meaningless on annotation types, but it does clarify that we may assign a meaning to such annotations in the future, whereas we plan not to assign any meaning to them on other class types.
If you agree, please add a thumbs-up emoji (👍) to this comment. If you disagree, please add a thumbs-down emoji (👎) to this comment and briefly explain your disagreement. Please only add a thumbs-down if you feel you can make a strong case why this decision will be materially worse for users or tool providers than an alternative. Note: A thumbs-up on the previous proposal will be considered a thumbs-up to this proposal as well.
❗EDIT on 2024-05-21: Please see the new proposal below (#7 (comment)).
GregDThomas commentedon May 7, 2024
I'm not adding a thumbs-down, as a mere bystander I'm sure I don't fully understand the reasoning behind this, but ..
I can't help but feel that this breaks the principle of least surprise, no? One is legal, the other is not.
Also, what about an interface that has default method? What will the implication be on those default methods? Why is that different from standard class methods?
netdpb commentedon May 7, 2024
Thanks for your comment!
To clarify:
We're talking about annotation types, so your second example should be
@Nullable @interface Bar {}. As you say, interfaces and classes are pretty similar and it would be surprising for JSpecify to treat them differently; but annotation types are very different from both, and so it's not so surprising if JSpecify treated them differently.The difference between "not legal" and "meaningless" is a fine one, and maybe "not legal" is a bad phrase. (I'll edit the revised proposal to remove "not legal".) The clarification I'm trying to make here is that although the annotations in
@Nullable class Foo {}and@Nullable @interface Bar {}are both meaningless in JSpecify 1.0, the latter may have some meaning in a future version of JSpecify.Does that help?
GregDThomas commentedon May 7, 2024
It does, yes. Sorry, somehow missed the @interface vs interface distinction!
wmdietl commentedon May 8, 2024
I find the updated proposal text confusing.
JSpecify 1.0 will not allow its type-use annotations (@Nullable and @NonNull) to apply to general class declarations.I'm not sure what a "general class declaration" is, but here the annotations are "not allowed".
Then later:
The annotation in @Nullable class Foo {} is meaningless, as is the one in @Nullable @interface Bar {}, but the latter may become meaningful in a future version of JSpecify.Here the proposal uses "meaningless" for both cases.
So are the annotations "not allowed" or "meaningless"?
kevinb9n commentedon May 8, 2024
JSpecify specifies which type usages are nullness-applicable. We should add that only type usages can be nullness-applicable, not any of the other places type-use annotations can go.
Have we ever put anything else in this category "meaningless but reserved"? If not, I would much rather not casually start down that road. I would like putting a nullness annotation on a class declaration to be forever meaningless, because whatever meaning we might like it to have in the future, we would do better to define a new annotation to express that more clearly anyway. We can get into why, but not here/now.
So, 👎🏼 on the proposal. [resolved below, yay!]
cpovirk commentedon May 8, 2024
My perspective would be that we need to make a decision for 1.0, and the only decision we can make for 1.0 is between "This is applicable with meaning x" and "This is not applicable." Any discussion of what might happen in the future is out of scope. In that respect, I'd see this issue as the same as all the other 1.0 issues, and I wouldn't try to differentiate is as "reserved," nor would I attempt to commit now to never using it. Neither strikes me as necessary: Those two options are exactly the options that we leave open by saying that the annotation is inapplicable for 1.0. And part of our goal is to avoid having to block 1.0 on even the basic shape of the design of an implication/aliasing system.
netdpb commentedon May 21, 2024
New Proposal
This proposal is essentially the same as the original proposal.
Proposal: JSpecify will not allow its type-use annotations (
@Nullableand@NonNull) to apply to class (and interface, and annotation, etc.) declarations.This proposal does not mean that JSpecify won't implement a mechanism for one annotation to imply another in the future (#35 and friends).
If you agree, please add a thumbs-up emoji (👍) to this comment. If you disagree, please add a thumbs-down emoji (👎) to this comment and briefly explain your disagreement. Please only add a thumbs-down if you feel you can make a strong case why this decision will be materially worse for users or tool providers than an alternative. Note: A thumbs-up on the original proposal will be considered a thumbs-up to this proposal as well.
Results: Five 👍 (including the two people with 👎 and 👀 on the original proposal), no other votemojis.
netdpb commentedon Jun 13, 2024
Decision: JSpecify will not allow its type-use annotations (
@Nullableand@NonNull) to apply to class (and interface, and annotation, etc.) declarations.[-]Applicability of TYPE_USE annotations to class declarations [working decision: no][/-][+]Applicability of TYPE_USE annotations to class declarations[/+]