Skip to content

NPE in KSP when trying to add @Json to data-class property #166

Open
mitasov-ra opened this issue Jun 20, 2023 · 1 comment
Open

NPE in KSP when trying to add @Json to data-class property #166

mitasov-ra opened this issue Jun 20, 2023 · 1 comment
Assignees
Labels
lang: kotlin Related for Kotlin language module: database Related to module - database

Comments

@mitasov-ra
Copy link
Contributor

@Component
@Tag(Json::class)
class JsonJdbcParameterColumnMapper<T>(private val writer: JsonWriter<T>) : JdbcParameterColumnMapper<T> {

  @Throws(SQLException::class)
  override fun set(stmt: PreparedStatement, index: Int, value: T?) {
    try {
      stmt.setString(index, String(writer.toByteArray(value), StandardCharsets.UTF_8))
    } catch (e: IOException) {
      throw SQLException(e)
    }
  }

}

@Repository
interface FooRepository {

    @Query("""
      INSERT INTO foo (bar)
      VALUES
      (:foo.bar::jsonb)
    """)
    fun insert(foo: Foo)
    
    @Query("""
      UPDATE foo
      SET bar = :bar::jsonb
    """)
    fun updateBar(@Json bar: Foo.Bar)
}

data class Foo(
  // @Json
  // should be added to make everything work
  val bar: Bar
) {
    data class Bar(val s: String)
}

If I uncomment // @Json :kspKotlin task fails with message:

> Task :kspKotlin FAILED
2 actionable tasks: 2 executed
e: [ksp] java.lang.NullPointerException
	at ru.tinkoff.kora.ksp.common.FieldFactory.get(FieldFactory.kt:26)
	at ru.tinkoff.kora.database.symbol.processor.jdbc.StatementSetterGenerator.generate(StatementSetterGenerator.kt:96)
	at ru.tinkoff.kora.database.symbol.processor.jdbc.JdbcRepositoryGenerator.generate(JdbcRepositoryGenerator.kt:89)
	at ru.tinkoff.kora.database.symbol.processor.jdbc.JdbcRepositoryGenerator.generate(JdbcRepositoryGenerator.kt:55)
	at ru.tinkoff.kora.database.symbol.processor.RepositoryBuilder.build(RepositoryBuilder.kt:50)
	at ru.tinkoff.kora.database.symbol.processor.RepositorySymbolProcessor.processClass(RepositorySymbolProcessor.kt:45)
	at ru.tinkoff.kora.database.symbol.processor.RepositorySymbolProcessor.access$processClass(RepositorySymbolProcessor.kt:15)
	at ru.tinkoff.kora.database.symbol.processor.RepositorySymbolProcessor$processRound$1.invoke(RepositorySymbolProcessor.kt:26)
	at ru.tinkoff.kora.database.symbol.processor.RepositorySymbolProcessor$processRound$1.invoke(RepositorySymbolProcessor.kt:26)
	at ru.tinkoff.kora.ksp.common.KspCommonUtilsKt$visitClass$1.visitClassDeclaration(KspCommonUtils.kt:208)
	at com.google.devtools.ksp.symbol.impl.kotlin.KSClassDeclarationImpl.accept(KSClassDeclarationImpl.kt:136)
	at ru.tinkoff.kora.ksp.common.KspCommonUtilsKt.visitClass(KspCommonUtils.kt:204)
	at ru.tinkoff.kora.database.symbol.processor.RepositorySymbolProcessor.processRound(RepositorySymbolProcessor.kt:26)
	at ru.tinkoff.kora.ksp.common.BaseSymbolProcessor.process(BaseSymbolProcessor.kt:87)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$6$1.invoke(KotlinSymbolProcessingExtension.kt:291)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$6$1.invoke(KotlinSymbolProcessingExtension.kt:289)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.handleException(KotlinSymbolProcessingExtension.kt:394)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.doAnalysis(KotlinSymbolProcessingExtension.kt:289)
	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:123)
	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:99)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:257)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:42)
	at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:115)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:248)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:88)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:47)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:168)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:53)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:100)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:46)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1486)
	at jdk.internal.reflect.GeneratedMethodAccessor52.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	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:833)

e: Error occurred in KSP, check log for detail

FAILURE: Build failed with an exception.
@mitasov-ra mitasov-ra changed the title NPE in KSP when trying to add @Json to data-class field NPE in KSP when trying to add @Json to data-class property Jun 20, 2023
@GoodforGod GoodforGod self-assigned this Jul 10, 2023
@GoodforGod GoodforGod added lang: kotlin Related for Kotlin language bug Something isn't working module: database Related to module - database labels Jul 10, 2023
@GoodforGod
Copy link
Contributor

Related to (#155)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang: kotlin Related for Kotlin language module: database Related to module - database
Projects
None yet
Development

No branches or pull requests

2 participants