Skip to content

@ConfigurationProperties annotated kotlin data classes containing properties with default value fail to initialize in 4.8.0 #11732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bfg opened this issue Apr 9, 2025 · 0 comments
Assignees
Labels

Comments

@bfg
Copy link
Contributor

bfg commented Apr 9, 2025

Expected Behavior

Assuming that you have configuration data class that is validated during initialization:

@ConfigurationProperties("app.controller")
data class ControllerCfg(
    val enabled: Boolean = true,
    @NotBlank val apiBase:String = "https://api.example.com/",
    @NotBlank val something: String = "some-value"
)

application configuration application.conf containing the following:

app {
  controller {
    enabled:    true
    #api-base:   "https://trololo.com/"
    something:  "trololo-something-value"
  }
}

This works perfectly fine on micronaut 4.7.6, but fails to initialize on 4.8.0 with:

Message: Validation failed for bean definition [com.github.bfg.mn48.ControllerCfg]
List of constraint violations:[
        com.github.bfg.mn48.ControllerCfg.apiBase - must not be blank
]
Path Taken:
new c.g.b.m.Controller(ControllerCfg cfg)
\---> new c.g.b.m.Controller([ControllerCfg cfg])
      \---> new @i.m.c.a.ConfigurationProperties("app.controller") c.g.b.m.ControllerCfg(boolean enabled, [String apiBase], String something)

It's obvious that apiBase property default value is not applied if it's absent in the config file. I really like and prefer 4.7.x behaviour in this context because some configuration constructs can be only easily specified in the code and have to be rarely changed in the actual config.

Actual Behaviour

Exception is being thrown

Steps To Reproduce

Reproducer: https://github.com/bfg/mn-48-kotlin-data-class-defvalue

Environment Information

  • OSX 15.2
  • JDK 21

Example Application

https://github.com/bfg/mn-48-kotlin-data-class-defvalue

Version

4.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Todo
Development

No branches or pull requests

3 participants