Skip to content

Fix dispatcher qualifier target#2114

Open
ois0886 wants to merge 1 commit into
android:mainfrom
ois0886:fix/issue-2001-dispatcher-target
Open

Fix dispatcher qualifier target#2114
ois0886 wants to merge 1 commit into
android:mainfrom
ois0886:fix/issue-2001-dispatcher-target

Conversation

@ois0886
Copy link
Copy Markdown

@ois0886 ois0886 commented May 21, 2026

What I have done and why

This PR adds explicit Kotlin annotation targets to the @Dispatcher qualifier.

@Dispatcher is used on injected value parameters and on Hilt provider functions, so the target list includes both VALUE_PARAMETER and FUNCTION. This keeps the qualifier usage explicit while preserving the existing provider declarations.

Fixes #2001

Testing

  • ./gradlew :core:common:test
  • ./gradlew :app:compileDemoDebugKotlin
  • ./gradlew :build-logic:convention:check
  • ./gradlew spotlessCheck
  • JAVA_HOME='/Applications/Android Studio.app/Contents/jbr/Contents/Home' ./gradlew testDemoDebug :lint:test
  • JAVA_HOME='/Applications/Android Studio.app/Contents/jbr/Contents/Home' ./gradlew dependencyGuard
  • JAVA_HOME='/Applications/Android Studio.app/Contents/jbr/Contents/Home' ./gradlew verifyRoborazziDemoDebug
  • JAVA_HOME='/Applications/Android Studio.app/Contents/jbr/Contents/Home' ./gradlew :app:assemble -PminifyWithR8=false
  • JAVA_HOME='/Applications/Android Studio.app/Contents/jbr/Contents/Home' ./gradlew :app:lintProdRelease :app-nia-catalog:lintRelease :lint:lint
  • JAVA_HOME='/Applications/Android Studio.app/Contents/jbr/Contents/Home' ./gradlew :app:checkProdReleaseBadging

@ois0886 ois0886 requested a review from dturner as a code owner May 21, 2026 05:22
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the @dispatcher qualifier annotation in NiaDispatchers.kt to explicitly define its targets as FUNCTION and VALUE_PARAMETER. Feedback suggests expanding these targets to include FIELD and PROPERTY to support field injection, which is a common requirement in Android development.

Comment on lines +21 to +25
import kotlin.annotation.AnnotationTarget.FUNCTION
import kotlin.annotation.AnnotationTarget.VALUE_PARAMETER

@Qualifier
@Target(FUNCTION, VALUE_PARAMETER)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When explicitly defining annotation targets for a Dagger qualifier in Kotlin, it is important to include FIELD and PROPERTY in addition to FUNCTION and VALUE_PARAMETER. This ensures that the qualifier can be used for field injection (e.g., in Activities or Fragments using lateinit var), which is a common pattern in Android development. Restricting it to only FUNCTION and VALUE_PARAMETER might break existing or future field injections.

Suggested change
import kotlin.annotation.AnnotationTarget.FUNCTION
import kotlin.annotation.AnnotationTarget.VALUE_PARAMETER
@Qualifier
@Target(FUNCTION, VALUE_PARAMETER)
import kotlin.annotation.AnnotationTarget.FIELD
import kotlin.annotation.AnnotationTarget.FUNCTION
import kotlin.annotation.AnnotationTarget.PROPERTY
import kotlin.annotation.AnnotationTarget.VALUE_PARAMETER
@Qualifier
@Target(FIELD, VALUE_PARAMETER, FUNCTION, PROPERTY)

Copy link
Copy Markdown
Author

@ois0886 ois0886 May 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I kept the target list scoped to the current usages in this project and to #2001.

@Dispatcher is currently used on Hilt provider functions and injected value parameters, so this PR includes FUNCTION and VALUE_PARAMETER. I left out FIELD and PROPERTY because there are no current field/property injection usages for this qualifier, and adding them would broaden the allowed targets beyond the issue's requested restriction.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the @dispatcher annotation in NiaDispatchers.kt to explicitly define its target as FUNCTION and VALUE_PARAMETER. Feedback suggests expanding these targets to include FIELD and PROPERTY to better support field injection in Android components and prevent potential compilation errors.

Comment on lines +21 to +25
import kotlin.annotation.AnnotationTarget.FUNCTION
import kotlin.annotation.AnnotationTarget.VALUE_PARAMETER

@Qualifier
@Target(FUNCTION, VALUE_PARAMETER)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To support field injection (common in Android components like Activities and Fragments) and to ensure compatibility with various Kotlin property usage patterns, it is recommended to include FIELD and PROPERTY in the @Target list. This prevents potential compilation errors when the qualifier is used on properties outside of constructor parameters.

Suggested change
import kotlin.annotation.AnnotationTarget.FUNCTION
import kotlin.annotation.AnnotationTarget.VALUE_PARAMETER
@Qualifier
@Target(FUNCTION, VALUE_PARAMETER)
import kotlin.annotation.AnnotationTarget.FIELD
import kotlin.annotation.AnnotationTarget.FUNCTION
import kotlin.annotation.AnnotationTarget.PROPERTY
import kotlin.annotation.AnnotationTarget.VALUE_PARAMETER
@Qualifier
@Target(FIELD, FUNCTION, PROPERTY, VALUE_PARAMETER)

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 this pull request may close these issues.

Restrict @Dispatcher qualifier to constructor parameters

1 participant