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

ErrorProne flags Subscribe annotated methods as UnusedMethod #6281

Closed
bright-tools opened this issue Dec 23, 2022 · 3 comments
Closed

ErrorProne flags Subscribe annotated methods as UnusedMethod #6281

bright-tools opened this issue Dec 23, 2022 · 3 comments
Labels
P2 package=eventbus type=defect Bug, not working as expected

Comments

@bright-tools
Copy link

bright-tools commented Dec 23, 2022

We've found that ErrorProne flags all @Subscribe annotated methods with an UnusedMethod warning

ErrorProne has a Keep annotation which could be applied to the Subscribe annotation in order to avoid this.

The alternatives seem to be suppressing the warning for each method or adding the subscribe annotation to a growing exemption list.

Would you be open to a PR to annotate Subscribe with @keep?

@cpovirk
Copy link
Member

cpovirk commented Dec 27, 2022

Thanks. It looks like UnusedMethod has a special case for @Subscribe already, but it's accidentally set up only for our internal builds.

That special case predates the creation of @Keep, so @Keep wasn't an option back then. We'll either add @Keep now or make the special case public.

@cpovirk cpovirk added type=defect Bug, not working as expected package=eventbus P2 labels Dec 27, 2022
@cpovirk
Copy link
Member

cpovirk commented Dec 27, 2022

(I should always take EventBus bugs as an opportunity to point people to our docs that recommend against using it if you can help it. But we should fix this regardless.)

copybara-service bot pushed a commit to google/error-prone that referenced this issue Dec 27, 2022
…aliper.Benchmark, com.google.common.eventbus.Subscribe, and com.google.inject.throwingproviders.CheckedProvides.

Fixes google/guava#6281

PiperOrigin-RevId: 497961342
copybara-service bot pushed a commit to google/error-prone that referenced this issue Dec 27, 2022
…aliper.Benchmark, com.google.common.eventbus.Subscribe, and com.google.inject.throwingproviders.CheckedProvides.

Fixes google/guava#6281

PiperOrigin-RevId: 497980825
@cpovirk
Copy link
Member

cpovirk commented Dec 27, 2022

This will be fixed in the next Error Prone release.

It's probably true that @Keep would be better. Hopefully that, like the special case in Error Prone, would work even if users omit error_prone_annotations from their own builds (though we recommend against that). I went with the fix on the Error Prone side just because it was slightly easier, especially to handle more annotations than just Guava's.

@cpovirk cpovirk closed this as completed Dec 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 package=eventbus type=defect Bug, not working as expected
Projects
None yet
2 participants