Skip to content

Unable to use Kotlin enums with @Validated beans [SPR-16931] #21470

Closed
@spring-projects-issues

Description

@spring-projects-issues

Daniel Jones opened SPR-16931 and commented

I have a configuration properties kotlin class with a kotlin enum property. If the class is annotated with @Validated an exception occurs in hibernate-validator's ParameterMetadata class due to an IndexOutOfBoundsException.

This seems to happen due to the underlying ParameterNameDiscoverer, KotlinReflectionParameterNameDiscoverer.

I think this is due to the validator class expecting a 2-parameter constructor (name, ordinal) but KotlinReflectionParameterNameDiscoverer returns an empty array.

Example configuration properties class:

@ConfigurationProperties("my.prefix")
@Validated
data class MyProperties(        
        var enumProp: MyEnum = MyEnum.ONE

) {
    enum class MyEnum {
        ONE, TWO
    }
} 

Affects: 5.0.6

Referenced from: commits 2c5a1af, 73db208

Backported to: 5.0.11

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions