Skip to content

jdk21+gradle9.0.0 启动,直接报错 java.lang.NullPointerException: translator.translate("Ktorm", null, ex) must not be null #13

Description

@yfsyfs

这个问题在 kotlin-orm/ktorm#376 描述过,问题的根因在于 org.ktorm.database.Database 的 connectWithSpringSupport 方法中使用的 exceptionTranslator 的类型是 public val exceptionTranslator: ((SQLException) -> Throwable)? = null,,但是 { ex -> translator.translate("Ktorm", null, ex) } 中 translator.translate("Ktorm", null, ex) 的 translator 是 spirng-jdbc 的 SQLErrorCodeSQLExceptionTranslator,而 SQLErrorCodeSQLExceptionTranslator 的 translate 返回的类型是允许 @nullable 的,所以导致了报错

kotlin-orm/ktorm#376 中也提出了解决方案,exceptionTranslator 的类型应该改成

public val exceptionTranslator: ((SQLException) -> Throwable?)? = null,

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