Skip to content

Applicability of TYPE_USE annotations to class declarations #7

Closed

Description

@dzharkov

The question was initially raised by @amaembo:

TYPE_USE annotation can be applied to class declaration. Does @nullable class X{} make sense?

Activity

  1. dzharkov commented on Nov 26, 2018

    @dzharkov
    CollaboratorAuthor

    Comments from the document:

    [@abreslav] I think such things should be reported as errors by the checker, unless we find a good meaning for them

  2. kevinb9n commented on Nov 26, 2018

    @kevinb9n
    Collaborator

    Agree with Andrey.

  3. added
    nullness
    on Nov 26, 2018
  4. kevin1e100 commented on Dec 20, 2018

    @kevin1e100
    Collaborator

    So noted

  5. wmdietlGC commented on Jan 10, 2019

    @wmdietlGC
    Collaborator

    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:

    @NotNull
    class Optional<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?

  6. cushon commented on Jan 10, 2019

    @cushon
    Collaborator
  7. wmdietlGC commented on Jan 10, 2019

    @wmdietlGC
    Collaborator

    I think there are two questions:

    1. Do we think class declaration annotations are useful for anyone to enforce this property?
    2. 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?

  8. kevin1e100 commented on Jan 10, 2019

    @kevin1e100
    Collaborator
  9. kevinb9n commented on Apr 19, 2019

    @kevinb9n
    Collaborator

    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.

  10. kevinb9n commented on Jun 12, 2019

    @kevinb9n
    Collaborator

    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.)

  11. kevinb9n commented on Jun 26, 2019

    @kevinb9n
    Collaborator

    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.

  12. kevinb9n commented on Jul 25, 2019

    @kevinb9n
    Collaborator

    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.

  13. 7 remaining items

  14. sdeleuze commented on Apr 10, 2024

    @sdeleuze
    Collaborator

    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.

  15. kevinb9n commented on Apr 10, 2024

    @kevinb9n
    Collaborator

    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]

  16. sdeleuze commented on Apr 10, 2024

    @sdeleuze
    Collaborator

    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.

  17. netdpb commented on May 7, 2024

    @netdpb
    Collaborator

    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)).

  18. GregDThomas commented on May 7, 2024

    @GregDThomas

    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?

  19. netdpb commented on May 7, 2024

    @netdpb
    Collaborator

    Thanks for your comment!

    @Nullable class Foo {} is not legal, but
    @Nullable interface Bar {} is [legal] meaningless ...

    To clarify:

    1. 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.

    2. 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?

  20. GregDThomas commented on May 7, 2024

    @GregDThomas

    It does, yes. Sorry, somehow missed the @interface vs interface distinction!

  21. wmdietl commented on May 8, 2024

    @wmdietl
    Collaborator

    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"?

  22. kevinb9n commented on May 8, 2024

    @kevinb9n
    Collaborator

    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!]

  23. cpovirk commented on May 8, 2024

    @cpovirk
    Collaborator

    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.

  24. netdpb commented on May 21, 2024

    @netdpb
    Collaborator

    New Proposal

    This proposal is essentially the same as the original proposal.

    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.

  25. netdpb commented on Jun 13, 2024

    @netdpb
    Collaborator

    Decision: JSpecify will not allow its type-use annotations (@Nullable and @NonNull) to apply to class (and interface, and annotation, etc.) declarations.

  26. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    designnullness

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions