From 83c020eea5386ba21f2f4bd74fb4167211b219fa Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Wed, 15 Jan 2025 12:58:20 +0000 Subject: [PATCH] Remove deprecated HttpStatus codes See gh-33809 --- .../servlet/result/StatusResultMatchers.java | 66 ------------------- .../org/springframework/http/HttpStatus.java | 61 ----------------- .../springframework/http/HttpStatusTests.java | 44 ------------- 3 files changed, 171 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/StatusResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/StatusResultMatchers.java index 65fc10f9472..f4d74c238a0 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/StatusResultMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/StatusResultMatchers.java @@ -255,16 +255,6 @@ public class StatusResultMatchers { return matcher(HttpStatus.FOUND); } - /** - * Assert the response status code is {@code HttpStatus.MOVED_TEMPORARILY} (302). - * @see #isFound() - * @deprecated in favor of {@link #isFound()} - */ - @Deprecated - public ResultMatcher isMovedTemporarily() { - return matcher(HttpStatus.MOVED_TEMPORARILY); - } - /** * Assert the response status code is {@code HttpStatus.SEE_OTHER} (303). */ @@ -279,15 +269,6 @@ public class StatusResultMatchers { return matcher(HttpStatus.NOT_MODIFIED); } - /** - * Assert the response status code is {@code HttpStatus.USE_PROXY} (305). - * @deprecated matching the deprecation of {@code HttpStatus.USE_PROXY} - */ - @Deprecated - public ResultMatcher isUseProxy() { - return matcher(HttpStatus.USE_PROXY); - } - /** * Assert the response status code is {@code HttpStatus.TEMPORARY_REDIRECT} (307). */ @@ -401,16 +382,6 @@ public class StatusResultMatchers { return matcher(HttpStatus.PAYLOAD_TOO_LARGE); } - /** - * Assert the response status code is {@code HttpStatus.REQUEST_ENTITY_TOO_LARGE} (413). - * @see #isPayloadTooLarge() - * @deprecated matching the deprecation of {@code HttpStatus.REQUEST_ENTITY_TOO_LARGE} - */ - @Deprecated - public ResultMatcher isRequestEntityTooLarge() { - return matcher(HttpStatus.REQUEST_ENTITY_TOO_LARGE); - } - /** * Assert the response status code is {@code HttpStatus.REQUEST_URI_TOO_LONG} (414). * @since 4.1 @@ -419,16 +390,6 @@ public class StatusResultMatchers { return matcher(HttpStatus.URI_TOO_LONG); } - /** - * Assert the response status code is {@code HttpStatus.REQUEST_URI_TOO_LONG} (414). - * @see #isUriTooLong() - * @deprecated matching the deprecation of {@code HttpStatus.REQUEST_URI_TOO_LONG} - */ - @Deprecated - public ResultMatcher isRequestUriTooLong() { - return matcher(HttpStatus.REQUEST_URI_TOO_LONG); - } - /** * Assert the response status code is {@code HttpStatus.UNSUPPORTED_MEDIA_TYPE} (415). */ @@ -457,33 +418,6 @@ public class StatusResultMatchers { return matcher(HttpStatus.valueOf(418)); } - /** - * Assert the response status code is {@code HttpStatus.INSUFFICIENT_SPACE_ON_RESOURCE} (419). - * @deprecated matching the deprecation of {@code HttpStatus.INSUFFICIENT_SPACE_ON_RESOURCE} - */ - @Deprecated - public ResultMatcher isInsufficientSpaceOnResource() { - return matcher(HttpStatus.INSUFFICIENT_SPACE_ON_RESOURCE); - } - - /** - * Assert the response status code is {@code HttpStatus.METHOD_FAILURE} (420). - * @deprecated matching the deprecation of {@code HttpStatus.METHOD_FAILURE} - */ - @Deprecated - public ResultMatcher isMethodFailure() { - return matcher(HttpStatus.METHOD_FAILURE); - } - - /** - * Assert the response status code is {@code HttpStatus.DESTINATION_LOCKED} (421). - * @deprecated matching the deprecation of {@code HttpStatus.DESTINATION_LOCKED} - */ - @Deprecated - public ResultMatcher isDestinationLocked() { - return matcher(HttpStatus.DESTINATION_LOCKED); - } - /** * Assert the response status code is {@code HttpStatus.UNPROCESSABLE_ENTITY} (422). */ diff --git a/spring-web/src/main/java/org/springframework/http/HttpStatus.java b/spring-web/src/main/java/org/springframework/http/HttpStatus.java index 0c6587162d4..0fd97ae18db 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpStatus.java +++ b/spring-web/src/main/java/org/springframework/http/HttpStatus.java @@ -127,13 +127,6 @@ public enum HttpStatus implements HttpStatusCode { * @see HTTP/1.1: Semantics and Content, section 6.4.3 */ FOUND(302, Series.REDIRECTION, "Found"), - /** - * {@code 302 Moved Temporarily}. - * @see HTTP/1.0, section 9.3 - * @deprecated in favor of {@link #FOUND} which will be returned from {@code HttpStatus.valueOf(302)} - */ - @Deprecated - MOVED_TEMPORARILY(302, Series.REDIRECTION, "Moved Temporarily"), /** * {@code 303 See Other}. * @see HTTP/1.1: Semantics and Content, section 6.4.4 @@ -144,13 +137,6 @@ public enum HttpStatus implements HttpStatusCode { * @see HTTP/1.1: Conditional Requests, section 4.1 */ NOT_MODIFIED(304, Series.REDIRECTION, "Not Modified"), - /** - * {@code 305 Use Proxy}. - * @see HTTP/1.1: Semantics and Content, section 6.4.5 - * @deprecated due to security concerns regarding in-band configuration of a proxy - */ - @Deprecated - USE_PROXY(305, Series.REDIRECTION, "Use Proxy"), /** * {@code 307 Temporary Redirect}. * @see HTTP/1.1: Semantics and Content, section 6.4.7 @@ -239,14 +225,6 @@ public enum HttpStatus implements HttpStatusCode { * HTTP/1.1: Semantics and Content, section 6.5.11 */ PAYLOAD_TOO_LARGE(413, Series.CLIENT_ERROR, "Payload Too Large"), - /** - * {@code 413 Request Entity Too Large}. - * @see HTTP/1.1, section 10.4.14 - * @deprecated in favor of {@link #PAYLOAD_TOO_LARGE} which will be - * returned from {@code HttpStatus.valueOf(413)} - */ - @Deprecated - REQUEST_ENTITY_TOO_LARGE(413, Series.CLIENT_ERROR, "Request Entity Too Large"), /** * {@code 414 URI Too Long}. * @since 4.1 @@ -254,13 +232,6 @@ public enum HttpStatus implements HttpStatusCode { * HTTP/1.1: Semantics and Content, section 6.5.12 */ URI_TOO_LONG(414, Series.CLIENT_ERROR, "URI Too Long"), - /** - * {@code 414 Request-URI Too Long}. - * @see HTTP/1.1, section 10.4.15 - * @deprecated in favor of {@link #URI_TOO_LONG} which will be returned from {@code HttpStatus.valueOf(414)} - */ - @Deprecated - REQUEST_URI_TOO_LONG(414, Series.CLIENT_ERROR, "Request-URI Too Long"), /** * {@code 415 Unsupported Media Type}. * @see @@ -283,27 +254,6 @@ public enum HttpStatus implements HttpStatusCode { * @see HTCPCP/1.0 */ I_AM_A_TEAPOT(418, Series.CLIENT_ERROR, "I'm a teapot"), - /** - * @deprecated See - * - * WebDAV Draft Changes - */ - @Deprecated - INSUFFICIENT_SPACE_ON_RESOURCE(419, Series.CLIENT_ERROR, "Insufficient Space On Resource"), - /** - * @deprecated See - * - * WebDAV Draft Changes - */ - @Deprecated - METHOD_FAILURE(420, Series.CLIENT_ERROR, "Method Failure"), - /** - * @deprecated - * See - * WebDAV Draft Changes - */ - @Deprecated - DESTINATION_LOCKED(421, Series.CLIENT_ERROR, "Destination Locked"), /** * {@code 422 Unprocessable Entity}. * @see WebDAV @@ -551,17 +501,6 @@ public enum HttpStatus implements HttpStatusCode { return this.value; } - /** - * Return the {@code Series} enum constant for the supplied {@code HttpStatus}. - * @param status a standard HTTP status enum constant - * @return the {@code Series} enum constant for the supplied {@code HttpStatus} - * @deprecated as of 5.3, in favor of invoking {@link HttpStatus#series()} directly - */ - @Deprecated - public static Series valueOf(HttpStatus status) { - return status.series; - } - /** * Return the {@code Series} enum constant for the supplied status code. * @param statusCode the HTTP status code (potentially non-standard) diff --git a/spring-web/src/test/java/org/springframework/http/HttpStatusTests.java b/spring-web/src/test/java/org/springframework/http/HttpStatusTests.java index 2a7328fcd23..d3818a8bfe4 100644 --- a/spring-web/src/test/java/org/springframework/http/HttpStatusTests.java +++ b/spring-web/src/test/java/org/springframework/http/HttpStatusTests.java @@ -17,19 +17,12 @@ package org.springframework.http; import java.util.LinkedHashMap; -import java.util.List; import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.params.provider.Arguments.arguments; /** * @author Arjen Poutsma @@ -62,7 +55,6 @@ class HttpStatusTests { statusCodes.put(302, "FOUND"); statusCodes.put(303, "SEE_OTHER"); statusCodes.put(304, "NOT_MODIFIED"); - statusCodes.put(305, "USE_PROXY"); statusCodes.put(307, "TEMPORARY_REDIRECT"); statusCodes.put(308, "PERMANENT_REDIRECT"); @@ -85,9 +77,6 @@ class HttpStatusTests { statusCodes.put(416, "REQUESTED_RANGE_NOT_SATISFIABLE"); statusCodes.put(417, "EXPECTATION_FAILED"); statusCodes.put(418, "I_AM_A_TEAPOT"); - statusCodes.put(419, "INSUFFICIENT_SPACE_ON_RESOURCE"); - statusCodes.put(420, "METHOD_FAILURE"); - statusCodes.put(421, "DESTINATION_LOCKED"); statusCodes.put(422, "UNPROCESSABLE_ENTITY"); statusCodes.put(423, "LOCKED"); statusCodes.put(424, "FAILED_DEPENDENCY"); @@ -127,9 +116,6 @@ class HttpStatusTests { void fromEnumToMap() { for (HttpStatus status : HttpStatus.values()) { int code = status.value(); - if (DEPRECATED_CODES.contains(status)) { - continue; - } assertThat(statusCodes).as("Map has no value for [" + code + "]").containsKey(code); assertThat(status.name()).as("Invalid name for [" + code + "]").isEqualTo(statusCodes.get(code)); } @@ -144,34 +130,4 @@ class HttpStatusTests { } } - @ParameterizedTest(name = "[{index}] code {0}") - @MethodSource("codesWithAliases") - void codeWithDeprecatedAlias(int code, HttpStatus expected, HttpStatus outdated) { - HttpStatus resolved = HttpStatus.valueOf(code); - assertThat(resolved) - .as("HttpStatus.valueOf(" + code + ")") - .isSameAs(expected) - .isNotEqualTo(outdated); - assertThat(outdated.isSameCodeAs(resolved)) - .as("outdated isSameCodeAs(resolved)") - .isTrue(); - assertThat(outdated.value()) - .as("outdated value()") - .isEqualTo(resolved.value()); - } - - private static final Set DEPRECATED_CODES = codesWithAliases() - .stream() - .map(args -> (HttpStatus) args.get()[2]) - .collect(Collectors.toUnmodifiableSet()); - - @SuppressWarnings("deprecation") - static List codesWithAliases() { - return List.of( - arguments(302, HttpStatus.FOUND, HttpStatus.MOVED_TEMPORARILY), - arguments(413, HttpStatus.PAYLOAD_TOO_LARGE, HttpStatus.REQUEST_ENTITY_TOO_LARGE), - arguments(414, HttpStatus.URI_TOO_LONG, HttpStatus.REQUEST_URI_TOO_LONG) - ); - } - }