Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot Assist-Inject kotlin.time.Duration #4605

Open
cohenItay opened this issue Feb 5, 2025 · 3 comments
Open

Cannot Assist-Inject kotlin.time.Duration #4605

cohenItay opened this issue Feb 5, 2025 · 3 comments

Comments

@cohenItay
Copy link

cohenItay commented Feb 5, 2025

versions:
Dagger 2.55
kotlin 2.1.10-RC
ksp 2.1.10-RC-1.0.29

code example:

interface Test {
    val sampleRate: Duration
    interface Factory {
        fun create(sampleRate: Duration) : Test
    }
}
internal class TestImpl @AssistedInject constructor(
    override val sampleRate: Duration
) : Test {

    @AssistedFactory
    interface Factory : Test.Factory {
        override fun create(sampleRate: Duration) : TestImpl
    }
}

build execption for gradle task :kspDebugKotlin:

[ksp] java.lang.IllegalArgumentException: not a valid name: create-LRDsOJo
	at com.squareup.javapoet.Util.checkArgument(Util.java:53)
	at com.squareup.javapoet.MethodSpec$Builder.setName(MethodSpec.java:315)
	at com.squareup.javapoet.MethodSpec$Builder.<init>(MethodSpec.java:310)
	at com.squareup.javapoet.MethodSpec$Builder.<init>(MethodSpec.java:294)
	at com.squareup.javapoet.MethodSpec.methodBuilder(MethodSpec.java:188)
	at dagger.internal.codegen.xprocessing.MethodSpecs.overriding(MethodSpecs.java:41)
	at dagger.internal.codegen.processingstep.AssistedFactoryProcessingStep$AssistedFactoryImplGenerator.topLevelTypes(AssistedFactoryProcessingStep.java:305)
	at dagger.internal.codegen.processingstep.AssistedFactoryProcessingStep$AssistedFactoryImplGenerator.topLevelTypes(AssistedFactoryProcessingStep.java:230)
	at dagger.internal.codegen.base.SourceFileGenerator.generate(SourceFileGenerator.java:72)
	at dagger.internal.codegen.processingstep.AssistedFactoryProcessingStep.process(AssistedFactoryProcessingStep.java:115)
	at dagger.internal.codegen.processingstep.AssistedFactoryProcessingStep.process(AssistedFactoryProcessingStep.java:78)
	at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.lambda$process$0(TypeCheckingProcessingStep.java:94)
	at com.google.common.collect.SingletonImmutableBiMap.forEach(SingletonImmutableBiMap.java:70)
	at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:72)
	at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:49)
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.XProcessingStep.process(XProcessingStep.kt:57)
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.CommonProcessorDelegate.processRound(XBasicAnnotationProcessor.kt:134)
	at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KspBasicAnnotationProcessor.process(KspBasicAnnotationProcessor.kt:62)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$8$1.invoke(KotlinSymbolProcessingExtension.kt:320)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$8$1.invoke(KotlinSymbolProcessingExtension.kt:318)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.handleException(KotlinSymbolProcessingExtension.kt:430)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.doAnalysis(KotlinSymbolProcessingExtension.kt:318)
	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:112)
	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:75)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze$lambda$9(KotlinToJVMBytecodeCompiler.kt:356)
	at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:112)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:347)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.runFrontendAndGenerateIrUsingClassicFrontend(KotlinToJVMBytecodeCompiler.kt:177)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:102)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:169)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:43)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:102)
	at org.jetbrains.kotlin.cli.common.CLICompiler.exec(CLICompiler.kt:316)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1706)
	at jdk.internal.reflect.GeneratedMethodAccessor89.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:360)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
	at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)

Once replacing the Duration with an Intit worked.

@bcorso
Copy link

bcorso commented Feb 5, 2025

Where is Test.Factory defined?

At first glance, this seems similar to Kotlin obfuscating internal method names, though your example doesn't use internal. If it's a similar issue, one workaround is to use @JvmName("create") on the create method to try to avoid Kotlin's obfuscation.

@cohenItay
Copy link
Author

You are correct my example was written incorrectly.
Iv'e added the internal and the the Factory declaration.

I'll try the create approach, is there any explanation in the docs to it? because I haven't found one

@danysantiago
Copy link
Member

You do need to help Dagger which generates Java and use @JvmName so it can invoke functions with inline classes such as kotlin.time.Duration from Java, see: https://kotlinlang.org/docs/inline-classes.html#calling-from-java-code

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

No branches or pull requests

3 participants