Skip to content

Bug Report: Kotlin anonymous enum constants fail to be recognized in TypeHandlerRegistry #3658

@Nitsuya

Description

@Nitsuya

About the Bug...

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of MyBatis.

  • I have confirmed this bug reproduces without 3rd party extensions (e.g. mybatis-plus).

Database Version

none

JDBC Driver Version

none

Issue Description

Description

In Kotlin, when an enum constant overrides an abstract method (creating an anonymous class), Class.isAnonymousClass returns false (unlike Java's behavior in some contexts). This causes TypeHandlerRegistry to fail when looking up TypeHandlers for these specific enum constants, as it may not correctly identify the base enum type.

Affected Code

File: TypeHandlerRegistry.java
Line: 268

Reproduction Steps

When using a Kotlin enum with anonymous class bodies like the following:

enum class TestEnum {
    TEST1 {
        override fun test() {
            println("test1")
        }
    };
    abstract fun test()
}

fun main() {
    // This prints "false" in Kotlin, which might bypass the current logic in MyBatis
    println(TestEnum.TEST1::class.java.isAnonymousClass) //false
    
    // However, it is a subclass of TestEnum
    println(TestEnum.TEST1.javaClass.superclass == TestEnum::class.java) // true
}

If you try to register or look up a TypeHandler for TestEnum.TEST1, MyBatis may fail to map it to the handler registered for TestEnum because it doesn't recognize it as an "anonymous class" that should be treated as its parent type.

Environment
MyBatis version: 3.5.19
Kotlin version: 1.9.25
Java version: 21

About your report...

  • I did not use images 🖼️ for showing text information (code, error, etc.).

  • I checked the Preview and my report looks awesome! 👍

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions