Skip to content

[KSP] Processing crash when two assisted inject constructors are encountered #3992

@ZacSweers

Description

@ZacSweers

The following code snippet

package com.squareup.test

import dagger.assisted.Assisted
import dagger.assisted.AssistedInject

class AssistedService @AssistedInject constructor(
  int: Int,
  @Assisted string: String
) {
  @AssistedInject constructor(@Assisted string: String)
}

will correctly error in apt with this message

Type com.squareup.test.AssistedService may only contain one injected constructor. Found: [@dagger.assisted.AssistedInject com.squareup.test.AssistedService, @dagger.assisted.AssistedInject com.squareup.test.AssistedService]

but will crash in KSP processing with the below trace. Note the message appears to be correct, but the crash is cause and reported after it's logged.

This is with Dagger version 2.47.

e: Error occurred in KSP, check log for detail
e: [ksp] /var/folders/nv/96k28mh96ml0g6y4gxkpjfcw0000gn/T/Kotlin-Compilation5455861261926387550/sources/src/main/java/com/squareup/test/Source0.kt:6: Type com.squareup.test.AssistedService may only contain one injected constructor. Found: [@dagger.assisted.AssistedInject com.squareup.test.AssistedService(int, String), @dagger.assisted.AssistedInject com.squareup.test.AssistedService(String)]
e: [ksp] java.lang.IllegalArgumentException: expected one element but was: <<init>, <init>>
	at com.google.common.collect.Iterators.getOnlyElement(Iterators.java:323)
	at com.google.common.collect.Iterables.getOnlyElement(Iterables.java:263)
	at dagger.internal.codegen.binding.AssistedInjectionAnnotations.assistedInjectAssistedParameters(AssistedInjectionAnnotations.java:257)
	at dagger.internal.codegen.processingstep.AssistedInjectProcessingStep$AssistedInjectValidator.validate(AssistedInjectProcessingStep.java:60)
	at dagger.internal.codegen.processingstep.AssistedInjectProcessingStep.process(AssistedInjectProcessingStep.java:51)
	at dagger.internal.codegen.processingstep.AssistedInjectProcessingStep.process(AssistedInjectProcessingStep.java:35)
	at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.lambda$process$0(TypeCheckingProcessingStep.java:82)
	at com.google.common.collect.RegularImmutableMap.forEach(RegularImmutableMap.java:196)
	at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:70)
	at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:48)
	at dagger.spi.shaded.androidx.room.compiler.processing.XProcessingStep.process(XProcessingStep.kt:59)
	at dagger.spi.shaded.androidx.room.compiler.processing.CommonProcessorDelegate.processRound(XBasicAnnotationProcessor.kt:130)
	at dagger.spi.shaded.androidx.room.compiler.processing.ksp.KspBasicAnnotationProcessor.process(KspBasicAnnotationProcessor.kt:62)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions