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

Detect premature use of @Inject properties #18

Open
jzbrooks opened this issue Jan 31, 2023 · 1 comment
Open

Detect premature use of @Inject properties #18

jzbrooks opened this issue Jan 31, 2023 · 1 comment

Comments

@jzbrooks
Copy link
Contributor

Hilt rewrites methods to inject android components at a certain point (early) in their lifecycles, so premature access of @Inject properties will usually result in a kotlin.UninitializedPropertyAccessException or an NRE in Java. https://dagger.dev/hilt/components#component-lifetimes

For example, if a Fragment references an @Inject property in its initializer (or implicitly does so by using it to initialize another property), the app will crash.

We should detect premature use of @Inject properties. The detector should be compatible with Java and Kotlin.

@jzbrooks
Copy link
Contributor Author

jzbrooks commented Jan 31, 2023

We could potentially offer this as a contribution upstream to Hilt.

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

No branches or pull requests

1 participant