Skip to content

Reactive Routes: invalid value for a converted @Param results in 500 instead of 400 #57828

Open

Description

@pschaub

Describe the bug

A reactive route parameter of a converted type (@Param Integer, Long, Boolean, …) results in 500 Internal Server Error when the request contains a value that cannot be converted, e.g. ?value=abc for an Integer. The generated handler catches the conversion failure and rethrows it as an IllegalArgumentException (ReactiveRoutesProcessor), which ends up in QuarkusErrorHandler as a 500.

Expected behavior

400 Bad Request, since the value comes from the client.

Actual behavior

500 Internal Server Error:

ERROR [io.quarkus.vertx.http.runtime.QuarkusErrorHandler] (vert.x-eventloop-thread-1) HTTP Request to /square?value=abc failed, error id: ...: java.lang.IllegalArgumentException: Error converting parameter #0 of method org.acme.Routes.square()
...
Caused by: java.lang.NumberFormatException: For input string: "abc"

How to Reproduce?

  1. Create a project:
    mvn io.quarkus.platform:quarkus-maven-plugin:3.40.1.1:create \
        -DprojectGroupId=org.acme -DprojectArtifactId=routes-repro \
        -Dextensions=reactive-routes -DnoCode
    cd routes-repro
  2. Add src/main/java/org/acme/Routes.java:
    package org.acme;
    
    import io.quarkus.vertx.web.Param;
    import io.quarkus.vertx.web.Route;
    
    public class Routes {
    
        @Route(path = "/square", methods = Route.HttpMethod.GET)
        String square(@Param Integer value) {
            return String.valueOf(value * value);
        }
    }
  3. Run ./mvnw quarkus:dev.
  4. Send requests:
    curl -s -o /dev/null -w "%{http_code}\n" 'localhost:8080/square?value=3'     # 200
    curl -s -o /dev/null -w "%{http_code}\n" 'localhost:8080/square?value=abc'   # 500

The same result with 4.0.0.Beta1 instead of 3.40.1.1 in step 1.

Output of uname -a or ver

Linux 6.18.54.1-microsoft-standard-WSL2 x86_64 GNU/Linux

Output of java -version

OpenJDK 21.0.12.1 (Temurin-21.0.12.1+1)

Quarkus version or git rev

3.40.1.1, 4.0.0.Beta1, main (5e98984)

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.9

Additional information

Similar to #57824, which covers malformed JSON in @Body parameters. I'll open a PR with a fix and a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions