Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-16931

Unable to use Kotlin enums with @Validated beans

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 5.0.6
    • Fix Version/s: 5.0.11, 5.1.2
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      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
          }
      } 

        Attachments

          Activity

            People

            Assignee:
            sdeleuze Sébastien Deleuze
            Reporter:
            jonesd9 Daniel Jones
            Last updater:
            Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Days since last comment:
              2 years, 2 weeks ago