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

KSP IllegalException "not a valid name" when using AssistedInject with Kotlin value class #4613

Open
jonapoul opened this issue Feb 17, 2025 · 0 comments

Comments

@jonapoul
Copy link

jonapoul commented Feb 17, 2025

I'm hitting a build error trying to use assisted injection with a HiltViewModel when injecting a @JvmInline value class.

An example that builds successfully, with a primitive type being injected:

@HiltViewModel(assistedFactory = TestViewModelPrimitive.Factory::class)
class TestViewModelPrimitive @AssistedInject constructor(
  @Assisted private val value: Int,
) : ViewModel() {
  @AssistedFactory
  interface Factory {
    fun create(value: Int): TestViewModelPrimitive
  }
}

and one that fails, when I change the injected parameter to a value class instead:

@HiltViewModel(assistedFactory = TestViewModelValueClass.Factory::class)
class TestViewModelValueClass @AssistedInject constructor(
  @Assisted private val value: MyValueClass,
) : ViewModel() {
  @AssistedFactory
  interface Factory {
    fun create(value: MyValueClass): TestViewModelValueClass
  }
}

@JvmInline
value class MyValueClass(val value: Int)

This fails on the kspDebugKotlin gradle task of my module - stack trace below:

[ksp] java.lang.IllegalArgumentException: not a valid name: create-e7Sson0
	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.RegularImmutableMap.forEach(RegularImmutableMap.java:297)
	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 java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	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:714)
	at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:598)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:844)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:721)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:720)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1583)

I've tried renaming the "create" factory method to various other things, plus renaming the variable and the class name - doesn't seem to affect anything.

This is with:

  • KSP v2.1.10-1.0.30
  • com.google.dagger.hilt.android plugin applied,
  • implementation("com.google.dagger:hilt-android:2.55")
  • ksp("com.google.dagger:hilt-compiler:2.55")

Let me know if you need any more info!

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

1 participant