@ -32,7 +32,6 @@ import org.springframework.context.support.StaticMessageSource;
@@ -32,7 +32,6 @@ import org.springframework.context.support.StaticMessageSource;
import org.springframework.core.MethodParameter ;
import org.springframework.http.HttpHeaders ;
import org.springframework.http.HttpMethod ;
import org.springframework.http.HttpStatus ;
import org.springframework.http.HttpStatusCode ;
import org.springframework.http.MediaType ;
import org.springframework.http.ProblemDetail ;
@ -267,6 +266,15 @@ public class ResponseEntityExceptionHandlerTests {
@@ -267,6 +266,15 @@ public class ResponseEntityExceptionHandlerTests {
testException ( new AsyncRequestTimeoutException ( ) ) ;
}
@Test // gh-14287, gh-31541
void serverErrorWithoutBody ( ) {
HttpStatusCode code = HttpStatusCode . valueOf ( 500 ) ;
Exception ex = new IllegalStateException ( "internal error" ) ;
this . exceptionHandler . handleExceptionInternal ( ex , null , new HttpHeaders ( ) , code , this . request ) ;
assertThat ( this . servletRequest . getAttribute ( "jakarta.servlet.error.exception" ) ) . isSameAs ( ex ) ;
}
@Test
public void controllerAdvice ( ) throws Exception {
StaticWebApplicationContext ctx = new StaticWebApplicationContext ( ) ;
@ -343,11 +351,6 @@ public class ResponseEntityExceptionHandlerTests {
@@ -343,11 +351,6 @@ public class ResponseEntityExceptionHandlerTests {
try {
ResponseEntity < Object > entity = this . exceptionHandler . handleException ( ex , this . request ) ;
// SPR-9653
if ( HttpStatus . INTERNAL_SERVER_ERROR . equals ( entity . getStatusCode ( ) ) ) {
assertThat ( this . servletRequest . getAttribute ( "jakarta.servlet.error.exception" ) ) . isSameAs ( ex ) ;
}
// Verify DefaultHandlerExceptionResolver would set the same status
this . exceptionResolver . resolveException ( this . servletRequest , this . servletResponse , null , ex ) ;
assertThat ( entity . getStatusCode ( ) . value ( ) ) . isEqualTo ( this . servletResponse . getStatus ( ) ) ;