snowdrop-zen / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
1 stars 0 forks source link

Spring Web: @ExceptionHandler response does not override @ResponseStatus #317

Closed snowdrop-bot closed 3 years ago

snowdrop-bot commented 3 years ago

Describe the bug

REST controller with an endpoint:

@RestController
@RequestMapping("/exception")
public class ExceptionController {

    @GetMapping
    @ResponseStatus(HttpStatus.OK)
    public String throwException() {
        throw new RuntimeException();
    }
}

Spring exception handler:

@RestControllerAdvice
public class RestExceptionHandler {
    @ExceptionHandler(RuntimeException.class)
    public ResponseEntity<Object> handleException(Exception ex) {
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }
}

The response should be 400 BAD REQUEST, but is 200 OK. Without the @ResponseStatus(HttpStatus.OK) annotation, the response is 400 BAD REQUEST. Without the @ExceptionHandler, the response is 500 Internal Server Error.

Expected behavior

Response status code is determined by @ExceptionHandler method response.

Actual behavior

Response status code is determined by @ResponseStatus endpoint annotation.

To Reproduce

quarkus-spring-web-bug-reproducer.zip

Steps to reproduce the behavior:

unzip quarkus-spring-web-bug-reproducer.zip && cd quarkus-spring-web-bug-reproducer
./mvnw clean verify

Environment (please complete the following information):

Output of java -version

openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.10+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.10+9, mixed mode)

GraalVM version

openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment GraalVM CE 20.3.1 (build 11.0.10+8-jvmci-20.3-b09)
OpenJDK 64-Bit Server VM GraalVM CE 20.3.1 (build 11.0.10+8-jvmci-20.3-b09, mixed mode, sharing)

Quarkus version

1.13.0.Final

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

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)

https://github.com/quarkusio/quarkus/issues/16321


$upstream:16321$