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

ZoneIdEditor throws wrong exception type for TypeConverterSupport #33545

Closed
harmonic-ben opened this issue Sep 17, 2024 · 0 comments
Closed

ZoneIdEditor throws wrong exception type for TypeConverterSupport #33545

harmonic-ben opened this issue Sep 17, 2024 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@harmonic-ben
Copy link

harmonic-ben commented Sep 17, 2024

Spring Framework Version: Latest (6.1.13) and below

spring-beans/src/main/java/org/springframework/beans/propertyeditors/ZoneIdEditor.java calls ZoneId.of which throws a java.time.DateTimeException.

But org.springframework.beans.TypeConverterSupport.convertIfNecessary(String, Object, Class<T>, TypeDescriptor) is expecting an IllegalArgumentException.

This manifests in a variety of ways. Best example is in web-mvc assuming a controller with:

   @GetMapping("/")
    public void get(
            @RequestParam(name = "integer", required = false)
            int integer,
            @RequestParam(name = "zoneId")
            ZoneId zoneId) {

    }

This means a get request of /?integer=helloworld results in a MethodArgumentTypeMismatchException which can easily be bound to 400 response.

However a get request of /?zoneId=helloworld results in a DateTimeException which binds to 500 response.

The integer parameter binding works because it throws NumberFormatException which extends from IllegalArgumentException.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 17, 2024
@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 17, 2024
@jhoeller jhoeller self-assigned this Sep 17, 2024
@jhoeller jhoeller added this to the 6.1.14 milestone Sep 17, 2024
@sbrannen sbrannen changed the title ZoneIdEditor wrong exception type for TypeConverterSupport ZoneIdEditor throws wrong exception type for TypeConverterSupport Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants