diff --git a/java/dagger/internal/codegen/binding/BindingGraphFactory.java b/java/dagger/internal/codegen/binding/BindingGraphFactory.java index e9bab739f47..ba1157d50bd 100644 --- a/java/dagger/internal/codegen/binding/BindingGraphFactory.java +++ b/java/dagger/internal/codegen/binding/BindingGraphFactory.java @@ -22,7 +22,6 @@ import static dagger.internal.codegen.base.Util.reentrantComputeIfAbsent; import static dagger.internal.codegen.binding.AssistedInjectionAnnotations.isAssistedFactoryType; import static dagger.internal.codegen.binding.SourceFiles.generatedMonitoringModuleName; -import static dagger.internal.codegen.extension.DaggerStreams.toImmutableSet; import static dagger.internal.codegen.model.BindingKind.ASSISTED_INJECTION; import static dagger.internal.codegen.model.BindingKind.DELEGATE; import static dagger.internal.codegen.model.BindingKind.INJECTION; @@ -48,6 +47,7 @@ import dagger.internal.codegen.base.ContributionType; import dagger.internal.codegen.base.DaggerSuperficialValidation; import dagger.internal.codegen.base.Keys; +import dagger.internal.codegen.base.MapType; import dagger.internal.codegen.base.OptionalType; import dagger.internal.codegen.compileroption.CompilerOptions; import dagger.internal.codegen.javapoet.TypeNames; @@ -521,17 +521,12 @@ private ImmutableSet keysMatchingRequestUncached(Key requestKey) { } private ImmutableSet createDelegateBindings( - ImmutableSetMultimap delegateDeclarations, Key requestKey) { - return delegateDeclarations.get( - // @Binds @IntoMap declarations have key Map, unlike @Provides @IntoMap or - // @Produces @IntoMap, which have Map> keys. So unwrap the - // key's type's value type if it's a Map> before looking - // in delegateDeclarations. createDelegateBindings() will create bindings with the - // properly wrapped key type. - keyFactory.unwrapMapValueType(requestKey)) - .stream() - .map(this::createDelegateBinding) - .collect(toImmutableSet()); + ImmutableSet delegateDeclarations) { + ImmutableSet.Builder builder = ImmutableSet.builder(); + for (DelegateDeclaration delegateDeclaration : delegateDeclarations) { + builder.add(createDelegateBinding(delegateDeclaration)); + } + return builder.build(); } /** @@ -704,9 +699,15 @@ private ImmutableList getResolverLineage() { * resolver. */ private ImmutableSet getLocalExplicitBindings(Key key) { - return ImmutableSet.builder() + return new ImmutableSet.Builder() .addAll(explicitBindings.get(key)) - .addAll(createDelegateBindings(delegateDeclarations, key)) + // @Binds @IntoMap declarations have key Map, unlike @Provides @IntoMap or @Produces + // @IntoMap, which have Map> keys. So unwrap the key's type's + // value type if it's a Map> before looking in + // delegateDeclarations. createDelegateBindings() will create bindings with the properly + // wrapped key type. + .addAll( + createDelegateBindings(delegateDeclarations.get(keyFactory.unwrapMapValueType(key)))) .build(); } @@ -715,10 +716,21 @@ private ImmutableSet getLocalExplicitBindings(Key key) { * by {@code key} from this resolver. */ private ImmutableSet getLocalExplicitMultibindings(Key key) { - return ImmutableSet.builder() - .addAll(explicitMultibindings.get(key)) - .addAll(createDelegateBindings(delegateMultibindingDeclarations, key)) - .build(); + ImmutableSet.Builder multibindings = ImmutableSet.builder(); + multibindings.addAll(explicitMultibindings.get(key)); + if (!MapType.isMap(key) + || MapType.from(key).isRawType() + || MapType.from(key).valuesAreFrameworkType()) { + // @Binds @IntoMap declarations have key Map, unlike @Provides @IntoMap or @Produces + // @IntoMap, which have Map> keys. So unwrap the key's type's + // value type if it's a Map> before looking in + // delegateMultibindingDeclarations. createDelegateBindings() will create bindings with the + // properly wrapped key type. + multibindings.addAll( + createDelegateBindings( + delegateMultibindingDeclarations.get(keyFactory.unwrapMapValueType(key)))); + } + return multibindings.build(); } /**