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

Suppress annotation on @Inject is not honored on the Factory #4302

Closed
BraisGabin opened this issue May 6, 2024 · 1 comment
Closed

Suppress annotation on @Inject is not honored on the Factory #4302

BraisGabin opened this issue May 6, 2024 · 1 comment

Comments

@BraisGabin
Copy link

I have a class that needs to inject a deprecated class. It looks like this:

public class Foo {
    @Inject
    @SuppressWarnings("deprecation")
    Foo(DeprecatedClass foo) {
    }
}

The generated Foo_Factory doesn't add the @SuppressWarning for "deprecation":

@ScopeMetadata
@QualifierMetadata
@DaggerGenerated
@Generated(
    value = "dagger.internal.codegen.ComponentProcessor",
    comments = "https://dagger.dev"
)
@SuppressWarnings({
    "unchecked",
    "rawtypes",
    "KotlinInternal",
    "KotlinInternalInJava",
    "cast"
})
public final class Foo_Factory implements Factory<Foo> {
  private final Provider<DeprecatedClass> fooProvider;

  public Foo_Factory(Provider<DeprecatedClass> fooProvider) {
    this.fooProvider = fooProvider;
  }
// ...

This prevents me to run java with -Werror active. I found that this feature exist on Hilt for other cases or at least that's what I understand from #2834.


Something similar happens when the deprecated class has the @Inject. The Factory also contains warning. Example:

@Deprecated("Don't use, please")
class DeprecatedClass @Inject constructor()

I found out this last one while writing this snippets for this issue so I don't care that much about it. And I'm not sure if it should be tracked in this issue or open a new one.

copybara-service bot pushed a commit that referenced this issue May 14, 2024
Fixes #4302.

RELNOTES=Suppress deprecation warnings in generated code. Fixes #4302
PiperOrigin-RevId: 633347320
@Chang-Eric
Copy link
Member

Thanks for letting us know. Unfortunately there isn't really a great way to decide when to copy this deprecation annotation over, as there isn't really a 1:1 correspondence since it isn't like we're copying a method or something. The deprecated usage in the constructor turns into needing to suppress it across the whole factory class. Presumably we'd also need to suppress it at the @Component level as well. So we ended up deciding to just always suppress this in all of our generated code since all of those usages should be coming from user code anyway (unless something really basic gets deprecated). I've submitted this change above.

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

Successfully merging a pull request may close this issue.

2 participants