Skip to content

ZoneIdEditor throws wrong exception type for TypeConverterSupport #33545

Closed

Description

@harmonic-ben

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.

Activity

  1. added
    status: waiting-for-triage
    on Sep 17, 2024
  2. added
    in: core
    type: bug
    and removed
    status: waiting-for-triage
    on Sep 17, 2024
  3. self-assigned this
    on Sep 17, 2024
  4. added this to the 6.1.14 milestone on Sep 17, 2024
  5. changed the title [-]ZoneIdEditor wrong exception type for TypeConverterSupport[/-] [+]`ZoneIdEditor` throws wrong exception type for `TypeConverterSupport`[/+] on Sep 17, 2024
  6. added a commit that references this issue on Sep 25, 2024
    ca04482
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions