Skip to content
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

Constructor binding fails for Duration argument if request parameter is not present #31709

Closed
cmdjulian opened this issue Nov 28, 2023 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: regression A bug that is also a regression
Milestone

Comments

@cmdjulian
Copy link

Affects:
Spring Web 6.1.1
Spring Boot 3.2.0

When having a Kotlin class as a container for request parameters with a default arg, this used to work without any problems up to Spring Boot 3.1.6. After switch to 3.2.0 the controller now throws an IllegalStateException Cannot resolve parameter names for constructor private java.time.Duration(long,int).

@RestController
class WebController {
    @GetMapping(path = ["/test"])
    fun test(container: RequestParameterContainer) = ResponseEntity.ofNullable(container)
}

data class RequestParameterContainer(val duration: Duration = Duration.parse("PT1H"))

When making the class mutable, for instance something like this, it works:

class RequestParameterContainerMutable {
    var duration: Duration = Duration.parse("PT1H")
}

I created a small reproducible for you. When setting a value for the parameter, it works. When omitting and the default should be triggered, instead the exception is thrown.

kotlin-default-bug.zip

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 28, 2023
@sdeleuze sdeleuze self-assigned this Nov 28, 2023
@sdeleuze sdeleuze added theme: kotlin An issue related to Kotlin support in: web Issues in web modules (web, webmvc, webflux, websocket) type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 28, 2023
@sdeleuze sdeleuze added this to the 6.1.2 milestone Nov 28, 2023
@sdeleuze sdeleuze removed the theme: kotlin An issue related to Kotlin support label Nov 30, 2023
@rstoyanchev
Copy link
Contributor

This is likely as a result of changes for #20806.

@rstoyanchev rstoyanchev assigned rstoyanchev and unassigned sdeleuze Dec 1, 2023
@rstoyanchev rstoyanchev changed the title Kotlin default args for Request Parameter Container throw IllegalStateException since Spring Boot 3.2.0 Constructor binding fails for Duration argument if request parameter is not present Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

4 participants