Skip to content

Can't use nullable types in Entities with Kotlin KSP #717

@Novalaina

Description

@Novalaina

I was hoping you could help me determine if this is the correct repository to report this error in. Given the stacktrace, I'm not sure if this is a problem with the Kotlin functionality you've recently added, or with kotlinpoet, or KSP itself.

Describe the bug
Using nullable values with Kotlin KSP causes an error. when trying to perform a build.

To Reproduce
I created a miniature repository that recreates the issue fully. Just run a gradle build in this project to fully recreate the problem.

kspnullerror repo

But all it takes is using KSP along with this code:

@Entity
class TestEntity(

    // Nullable Int causes failure
    val amount: Int?,

// Rest of the Entity

Expected behavior
I expect a gradle build to work.

Additional context
Full stacktrace:

[ksp] java.lang.IllegalStateException: KSType 'Comparable<Int>' has type arguments, which are not supported for ClassName conversion. Use KSType.toTypeName().
	at com.squareup.kotlinpoet.ksp.KsTypesKt.toClassName(KsTypes.kt:44)
	at com.querydsl.ksp.codegen.TypeExtractor.collectionType(TypeExtractor.kt:64)
	at com.querydsl.ksp.codegen.TypeExtractor.extract(TypeExtractor.kt:25)
	at com.querydsl.ksp.codegen.QueryModelExtractor.extractProperties$lambda$7(QueryModelExtractor.kt:79)
	at kotlin.sequences.TransformingSequence$iterator$1.next(Sequences.kt:210)
	at kotlin.sequences.SequencesKt___SequencesKt.toList(_Sequences.kt:820)
	at com.querydsl.ksp.codegen.QueryModelExtractor.extractProperties(QueryModelExtractor.kt:82)
	at com.querydsl.ksp.codegen.QueryModelExtractor.processProperties(QueryModelExtractor.kt:65)
	at com.querydsl.ksp.codegen.QueryModelExtractor.process(QueryModelExtractor.kt:34)
	at com.querydsl.ksp.codegen.QueryDslProcessor.finish(QueryDslProcessor.kt:29)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$12$1.invoke(KotlinSymbolProcessingExtension.kt:359)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$12$1.invoke(KotlinSymbolProcessingExtension.kt:358)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.handleException(KotlinSymbolProcessingExtension.kt:430)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.doAnalysis(KotlinSymbolProcessingExtension.kt:358)
	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:1554)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions