Skip to content

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

@cmdjulian

Description

@cmdjulian

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

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions