Faithlife / AndroidLint

Android Lint checks to enforce Faithlife house rules
MIT License
2 stars 2 forks source link

Detect premature use of @Inject properties #18

Open jzbrooks opened 1 year ago

jzbrooks commented 1 year ago

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 commented 1 year ago

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