From 058b0792f7348035a5b08a630606ef24eb491920 Mon Sep 17 00:00:00 2001 From: Xavier Garabito Date: Thu, 14 May 2026 14:56:28 -0700 Subject: [PATCH] Fix Dagger multibinding duplicate tracking for Maps Currently, Dagger only verifies duplicate map key contributions within the same component. Contributions with duplicate keys across the component hierarchy are ignored, resulting in masked values or runtime crashes when backed by Guava. This change introduces strict duplicate detection across the full map binding graph. Dagger now performs compile-time verification to reject duplicate map keys across the entire component hierarchy. This behavior is controlled by the new compiler option -Adagger.mapMultibindingDuplicateDetectionFix. When enabled, strict duplicate tracking is enforced across the component hierarchy. RELNOTES=Fixed Dagger multibinding duplicate masking across Map components (compile-time validation). PiperOrigin-RevId: 915631609 --- dev-guide/compiler-options.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/dev-guide/compiler-options.md b/dev-guide/compiler-options.md index 2b957bfa2fb..72bdc8bc50f 100644 --- a/dev-guide/compiler-options.md +++ b/dev-guide/compiler-options.md @@ -170,6 +170,23 @@ especially true when dealing with Kotlin sources, where wildcards must be interpreted indirectly from a number of factors other than the explicit variance at the use site. +## Detect duplicate map multibinding contributions across component boundaries {#map-multibinding-duplicate-detection-fix} + +The `dagger.mapMultibindingDuplicateDetectionFix` flag fixes a bug in Dagger +where duplicate multibinding map keys were allowed in certain situations. +When the flag is enabled Dagger should enforce strict duplicate checking of map +multibinding contributions (e.g., identical `@IntoMap` bindings) across +component boundaries. + +By default, this flag is disabled, meaning Dagger preserves the legacy lenient +behavior and ignores duplicate map key contributions across component +boundaries. + +To opt-in to strict duplicate detection at compile time (for Maps), enable the +flag by passing the following compiler option: + +`-Adagger.mapMultibindingDuplicateDetectionFix=ENABLED` + [`@Component`]: https://dagger.dev/api/latest/dagger/Component.html