Browse Source

Consistent ordering in MethodNotAllowedException

This caused random failures in a newly added test. Also remove defensive
check in ResponseStatusExceptionResolver.

See gh-24944
pull/24968/head
Rossen Stoyanchev 6 years ago
parent
commit
583435d068
  1. 4
      spring-web/src/main/java/org/springframework/web/server/MethodNotAllowedException.java
  2. 7
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java

4
spring-web/src/main/java/org/springframework/web/server/MethodNotAllowedException.java

@ -18,7 +18,7 @@ package org.springframework.web.server; @@ -18,7 +18,7 @@ package org.springframework.web.server;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
@ -54,7 +54,7 @@ public class MethodNotAllowedException extends ResponseStatusException { @@ -54,7 +54,7 @@ public class MethodNotAllowedException extends ResponseStatusException {
supportedMethods = Collections.emptySet();
}
this.method = method;
this.httpMethods = Collections.unmodifiableSet(new HashSet<>(supportedMethods));
this.httpMethods = Collections.unmodifiableSet(new LinkedHashSet<>(supportedMethods));
}

7
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java

@ -130,11 +130,8 @@ public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionRes @@ -130,11 +130,8 @@ public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionRes
protected ModelAndView resolveResponseStatusException(ResponseStatusException ex,
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws Exception {
ex.getResponseHeaders().forEach((name, values) -> {
if (response.getHeader(name) == null) {
values.forEach(value -> response.addHeader(name, value));
}
});
ex.getResponseHeaders().forEach((name, values) ->
values.forEach(value -> response.addHeader(name, value)));
int statusCode = ex.getStatus().value();
String reason = ex.getReason();

Loading…
Cancel
Save