Skip to content

Commit

Permalink
Consistent ordering in MethodNotAllowedException
Browse files Browse the repository at this point in the history
This caused random failures in a newly added test. Also remove defensive
check in ResponseStatusExceptionResolver.

See gh-24944
  • Loading branch information
rstoyanchev committed Apr 25, 2020
1 parent 2002a16 commit 583435d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
Expand Up @@ -18,7 +18,7 @@

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -54,7 +54,7 @@ public MethodNotAllowedException(String method, @Nullable Collection<HttpMethod>
supportedMethods = Collections.emptySet();
}
this.method = method;
this.httpMethods = Collections.unmodifiableSet(new HashSet<>(supportedMethods));
this.httpMethods = Collections.unmodifiableSet(new LinkedHashSet<>(supportedMethods));
}


Expand Down
Expand Up @@ -130,11 +130,8 @@ protected ModelAndView resolveResponseStatus(ResponseStatus responseStatus, Http
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();
Expand Down

0 comments on commit 583435d

Please sign in to comment.