You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Kotlin class instantiation with optional parameters and default values [SPR-15673] #20232
Following the work done on #19763, it seems we don't support currently Kotlin classes with default parameters since the bytecode generated contains 2 constructors.
This feature should if possible be reusable from Spring Boot for its support for @ConfigurationProperties and Spring Data which currently requires Kotlin noarg compiler plugin (I have validated it is currently required via MiXiT application, would be nice to be able to avoid using this plugin which is basicaly a trick for libraries without Kotlin support).
Juergen Hoeller I am going to try to write Kotlin tests that demonstrate the issue and try to find the right Kotlin API to use for that, I may need your guidance for the steps after that.
I would like to add that after the upgrade to Spring Boot 2.0.0 M3 this actually broke some Kotlin compability for me.
I had a @ConfigurationProperties class with a constructor that had default values for all parameters. This worked fine in M2
@ConfigurationProperties("foo")
class FooProperties(
var bar: String = "bar",
var baz: Int = 1
)
With M3 I get
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [de.techdev.xyz.FooProperties]: No corresponding Kotlin constructor found
at org.springframework.beans.BeanUtils$KotlinDelegate.instantiateClass(BeanUtils.java:742) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:165) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:88) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3]
So I had to change to
@ConfigurationProperties("foo")
class FooProperties {
var bar: String = "bar",
var baz: Int = 1
}
(which of cause is not that big of a hassle - I didn't use the constructor anywhere manually anyway).
This is a regression reported already 2 times, so maybe there is something to improve. Please create an issue in order to make sure I have a look before RC4.
Activity
spring-projects-issues commentedon Jun 23, 2017
Sébastien Deleuze commented
For the record, Jayson Minard provided these hints to help us based on his experience on the Jackson Kotlin module:
spring-projects-issues commentedon Jul 19, 2017
Sébastien Deleuze commented
Pull request submitted: #1482
spring-projects-issues commentedon Jul 27, 2017
Moritz Schulze commented
I would like to add that after the upgrade to Spring Boot 2.0.0 M3 this actually broke some Kotlin compability for me.
I had a
@ConfigurationPropertiesclass with a constructor that had default values for all parameters. This worked fine in M2With M3 I get
So I had to change to
(which of cause is not that big of a hassle - I didn't use the constructor anywhere manually anyway).
spring-projects-issues commentedon Jul 27, 2017
Sébastien Deleuze commented
Moritz Schulze Could you please create a dedicated issue describing this regression? I will have a look before RC4.
spring-projects-issues commentedon Jul 27, 2017
Moritz Schulze commented
I guess this ticket for Spring Boot will fix this in the end: spring-projects/spring-boot#8762, so maybe that is not necessary?
spring-projects-issues commentedon Aug 2, 2017
Sébastien Deleuze commented
This is a regression reported already 2 times, so maybe there is something to improve. Please create an issue in order to make sure I have a look before RC4.
spring-projects-issues commentedon Aug 7, 2017
Sébastien Deleuze commented
#20406 has been creted to track and fix this regression.