Skip to content

A meta-annotation to express "incompatible with <other annotations>" #101

Open

Description

@kevinb9n

For example imagine:

@IncompatibleWith({Nullable.class, NullUnspecified.class})
public @interface NonNull {...}

This would express that it is invalid to use this annotation and any of the listed ones together in the exact same spot. (Of course, it would not prevent two listed annotations from appearing together in the absence of the annotated annotation.)

By convention we could do it in both directions but only one would be necessary.

Activity

  1. kevinb9n commented on May 8, 2020

    @kevinb9n
    CollaboratorAuthor

    A compliant checker would not permit the conflicting annotations to appear together in code it is analyzing. But what if they appear together in some dependency of the code being analyzed?

    I would suggest that checkers absolutely should not choose based on position (even if that order is preserved in the class file). And trying to specify an order of precedence somehow feels like a big waste of complexity with little to gain. And deciding to just ignore them all won't lead to anything good.

    So, we might actually want the @IncompatibleWith docs to explicitly condone giving an error even if it's a dependency that contains the violation.

  2. mernst commented on May 8, 2020

    @mernst
    Contributor

    If there are annotations that express a subtyping relationship, such as @SubtypeOf, they can serve this purpose. We might still need @IncompatibleWith, but maybe not for type annotations.

  3. cpovirk commented on May 11, 2020

    @cpovirk
    Collaborator

    For jspecify, supporting this feels somewhat speculative to me, similar to how I feel about @NegatedBy/@NegatedOf.

    The Checker Framework, by contrast, has more reason to support @SubtypeOf: It is part of what lets users define arbitrary new type systems.

    Kevin has replied to my concerns on the other thread. I agree that there's some value to the annotations proposed in both this issue and #109, but both still feel to me to not be part of the minimum viable product.

  4. kevinb9n commented on May 11, 2020

    @kevinb9n
    CollaboratorAuthor

    (I can see making the actual release of said annotations lower priority, for sure. I just want us to be thinking ahead a bit, so that in 5 years we have a nice stable of stable annotations, where learning one actually helps you to learn another.)

  5. cpovirk commented on Feb 1, 2021

    @cpovirk
    Collaborator

    One potentially nice thing about meta-annotations in general is that it lets us make changes in the annotations themselves and then have the behavior change automatically picked up by tools. Alternatively, that is a potentially scary thing :) But I'm not sure if it's necessarily any scarier than the idea that we'd make significant changes to existing annotations period.

    This is similar to a discussion about using @Target vs. hardcoding that information in checkers.

  6. added this to the Post-1.0 milestone on Aug 18, 2021
  7. added
    design
    new-feature
    and removed
    design
    on Nov 30, 2022
  8. added
    design
    on Mar 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

    designnew-feature

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions