@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.
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)
Describe the bug
REST controller with an endpoint:
Spring exception handler:
The response should be
400 BAD REQUEST
, but is200 OK
. Without the@ResponseStatus(HttpStatus.OK)
annotation, the response is400 BAD REQUEST
. Without the@ExceptionHandler
, the response is500 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:
Environment (please complete the following information):
Output of
java -version
GraalVM version
Quarkus version
Build tool (ie. output of
mvnw --version
orgradlew --version
)https://github.com/quarkusio/quarkus/issues/16321
$upstream:16321$