Skip to content
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

Annotation targets and retentions for nullness annotations #96

Closed
kevin1e100 opened this issue Feb 22, 2020 · 3 comments
Closed

Annotation targets and retentions for nullness annotations #96

kevin1e100 opened this issue Feb 22, 2020 · 3 comments
Labels
design An issue that is resolved by making a decision, about whether and how something should work. nullness For issues specific to nullness analysis.
Milestone

Comments

@kevin1e100
Copy link
Collaborator

We've talked about using runtime retention for annotations unless there's a good reason not to, I believe. For nullness at least we're also looking at a combination of type-use annotations, such as @Nullable, and declaration annotations, such as @DefaultNonNull. Filing this issue to point out a potential pitfall for reflective tools, specifically on Android:

Type-use annotations can't be encoded in Android apps, currently, so there's no way to do runtime reflection on them. On the other hand, reflection is possible with declaration annotations. That creates the potentially confusing situation that runtime libraries that use reflection, when run on Android, may "see" @DefaultNonNull surrounding a method but not @Nullable on the method's return type, for instance, so they may erroneously conclude that the return type is non-null.

This potential confusion could be avoided with class retention, but that prevents any reflection on nullness annotations, even outside Android, which also seems unfortunate.

I'm not sure we need to do anything here, but I wanted to file this away for posterity.

@cpovirk
Copy link
Collaborator

cpovirk commented Feb 25, 2020

I agree that this is unfortunate -- hopefully only mildly so, especially since I don't see what we can do about it (other than giving up on runtime retention).

There isn't a way for us to ship a Proguard configuration that says to not keep a specific annotation, right? Or even if there is, that might be frowned upon, since the usual model is to specify what to keep, not what to remove.

One possible workaround in the long term is for users to declare their own alias for @DefaultNonNull, giving it only class retention.

cpovirk added a commit that referenced this issue Dec 15, 2020
@netdpb netdpb added this to the 1.0 milestone Oct 13, 2021
@kevinb9n kevinb9n added the nullness For issues specific to nullness analysis. label Oct 18, 2021
@kevinb9n
Copy link
Collaborator

kevinb9n commented Dec 8, 2021

This seems like a dup of #28.

@kevinb9n kevinb9n closed this as completed Dec 8, 2021
@cpovirk
Copy link
Collaborator

cpovirk commented Dec 8, 2021

(The intention was that this issue would capture anything nullness-specific, like Kevin's comments about the absence of type-use annotations at runtime for Android. But I don't think there's been enough concern about that to leave this one open.)

@kevinb9n kevinb9n added the design An issue that is resolved by making a decision, about whether and how something should work. label Nov 30, 2022
@kevinb9n kevinb9n modified the milestones: 1.0, 0.3 Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design An issue that is resolved by making a decision, about whether and how something should work. nullness For issues specific to nullness analysis.
Projects
None yet
Development

No branches or pull requests

4 participants