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

Make annotations class retention only #4797

Closed
laeubi opened this issue Jan 30, 2025 · 3 comments
Closed

Make annotations class retention only #4797

laeubi opened this issue Jan 30, 2025 · 3 comments

Comments

@laeubi
Copy link

laeubi commented Jan 30, 2025

I noticed some annotations are marked with RUNTIME retention policy. For the purpose of checking the code it seems enough to have CLASS retention policy.

@eamonnmcmanus
Copy link
Member

The current situation is a bit haphazard: some annotations have RUNTIME retention and some have CLASS. For example, @CheckReturnValue is RUNTIME but @CanIgnoreReturnValue (CIRV) is CLASS. We've tried promoting CIRV to RUNTIME in the past but ran into some issues with it causing extra classes to be retained when stripping Android apps.

Anyway, we are unlikely to change the retention of any annotation from RUNTIME to CLASS since that is an incompatible change. It seems quite likely that client code is relying on being able to detect at least some of these annotations at runtime. For example, Mockito checks its own @DoNotMock annotation at runtime, and code could be doing the same for Error Prone's.

@eamonnmcmanus eamonnmcmanus closed this as not planned Won't fix, can't repro, duplicate, stale Jan 31, 2025
@cushon
Copy link
Collaborator

cushon commented Jan 31, 2025

There is some related discussion about RUNTIME vs. CLASS for JSpecify (jspecify/jspecify#28), I think the plan there is to generally use RUNTIME for new annotations

@laeubi
Copy link
Author

laeubi commented Jan 31, 2025

It seems quite likely that client code is relying on being able to detect at least some of these annotations at runtime.

I can actually not think of any case where it is useful... Mockito is working on the runtime so it needs RUNTIME but for compiler or tool scoped annotation like error prone there is no benefit I can think of.

We've tried promoting CIRV to RUNTIME in the past but ran into some issues with it causing extra classes to be retained when stripping Android apps.

That's why I propose to put everything to CLASS, as RUNTIME has some unwanted implications and actually makes erroprone dripping into the runtime for no good reasons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants