Skip to content

Commit eb15b26

Browse files
committed
Add since and forRemoval to @deprecated
1 parent 5f6df35 commit eb15b26

File tree

10 files changed

+51
-55
lines changed

10 files changed

+51
-55
lines changed

spring-web/src/main/java/org/springframework/http/HttpEntity.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -107,9 +107,9 @@ public HttpEntity(@Nullable T body, @Nullable HttpHeaders headers) {
107107
/**
108108
* Create a new {@code HttpEntity} with the given headers and no body.
109109
* @param headers the entity headers
110-
* @deprecated Use {@link #HttpEntity(HttpHeaders)}
110+
* @deprecated in favor of {@link #HttpEntity(HttpHeaders)}
111111
*/
112-
@Deprecated
112+
@Deprecated(since = "7.0", forRemoval = true)
113113
public HttpEntity(MultiValueMap<String, String> headers) {
114114
this(null, headers);
115115
}
@@ -118,9 +118,9 @@ public HttpEntity(MultiValueMap<String, String> headers) {
118118
* Create a new {@code HttpEntity} with the given body and headers.
119119
* @param body the entity body
120120
* @param headers the entity headers
121-
* @deprecated Use {@link #HttpEntity(Object, HttpHeaders)}
121+
* @deprecated in favor of {@link #HttpEntity(Object, HttpHeaders)}
122122
*/
123-
@Deprecated
123+
@Deprecated(since = "7.0", forRemoval = true)
124124
public HttpEntity(@Nullable T body, @Nullable MultiValueMap<String, String> headers) {
125125
this.body = body;
126126
this.headers = HttpHeaders.readOnlyHttpHeaders(headers != null ? new HttpHeaders(headers) : new HttpHeaders());

spring-web/src/main/java/org/springframework/http/HttpHeaders.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1847,11 +1847,11 @@ public Map<String, String> toSingleValueMap() {
18471847
* casing variants of a given header name, see {@link #asMultiValueMap()}
18481848
* javadoc.
18491849
* @return a single value representation of these headers
1850-
* @deprecated Use {@link #toSingleValueMap()} which performs a copy but
1850+
* @deprecated in favor of {@link #toSingleValueMap()} which performs a copy but
18511851
* ensures that collection-iterating methods like {@code entrySet()} are
18521852
* case-insensitive
18531853
*/
1854-
@Deprecated
1854+
@Deprecated(since = "7.0", forRemoval = true)
18551855
public Map<String, String> asSingleValueMap() {
18561856
return this.headers.asSingleValueMap();
18571857
}
@@ -1870,7 +1870,7 @@ public Map<String, String> asSingleValueMap() {
18701870
* that would only accept maps. Generally avoid using HttpHeaders as a Map
18711871
* or MultiValueMap.
18721872
*/
1873-
@Deprecated
1873+
@Deprecated(since = "7.0", forRemoval = true)
18741874
public MultiValueMap<String, String> asMultiValueMap() {
18751875
return this.headers;
18761876
}

spring-web/src/main/java/org/springframework/http/ReadOnlyHttpHeaders.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -120,14 +120,16 @@ public Map<String, String> toSingleValueMap() {
120120
return Collections.unmodifiableMap(this.headers.toSingleValueMap());
121121
}
122122

123+
@SuppressWarnings("removal")
123124
@Override
124-
@Deprecated
125+
@Deprecated(since = "7.0", forRemoval = true)
125126
public Map<String, String> asSingleValueMap() {
126127
return Collections.unmodifiableMap(this.headers.asSingleValueMap());
127128
}
128129

130+
@SuppressWarnings("removal")
129131
@Override
130-
@Deprecated
132+
@Deprecated(since = "7.0", forRemoval = true)
131133
public MultiValueMap<String, String> asMultiValueMap() {
132134
return CollectionUtils.unmodifiableMultiValueMap(this.headers);
133135
}

spring-web/src/main/java/org/springframework/http/RequestEntity.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ public RequestEntity(@Nullable T body, @Nullable HttpHeaders headers,
152152
* @param headers the headers
153153
* @param method the method
154154
* @param url the URL
155-
* @deprecated Use {@link #RequestEntity(HttpHeaders, HttpMethod, URI)}
155+
* @deprecated in favor of {@link #RequestEntity(HttpHeaders, HttpMethod, URI)}
156156
*/
157-
@Deprecated
157+
@Deprecated(since = "7.0", forRemoval = true)
158158
public RequestEntity(MultiValueMap<String, String> headers, HttpMethod method, URI url) {
159159
this(null, headers, method, url, null);
160160
}
@@ -165,10 +165,11 @@ public RequestEntity(MultiValueMap<String, String> headers, HttpMethod method, U
165165
* @param headers the headers
166166
* @param method the method
167167
* @param url the URL
168-
* @deprecated Use {@link #RequestEntity(Object, HttpHeaders, HttpMethod, URI)}
168+
* @deprecated in favor of {@link #RequestEntity(Object, HttpHeaders, HttpMethod, URI)}
169169
*/
170-
@Deprecated
171-
public RequestEntity(@Nullable T body, @Nullable MultiValueMap<String, String> headers,
170+
@Deprecated(since = "7.0", forRemoval = true)
171+
public RequestEntity(
172+
@Nullable T body, @Nullable MultiValueMap<String, String> headers,
172173
@Nullable HttpMethod method, URI url) {
173174

174175
this(body, headers, method, url, null);
@@ -182,9 +183,10 @@ public RequestEntity(@Nullable T body, @Nullable MultiValueMap<String, String> h
182183
* @param url the URL
183184
* @param type the type used for generic type resolution
184185
* @since 4.3
185-
* @deprecated Use {@link #RequestEntity(Object, HttpHeaders, HttpMethod, URI, Type)}
186+
* @deprecated in favor of {@link #RequestEntity(Object, HttpHeaders, HttpMethod, URI, Type)}
186187
*/
187-
@Deprecated
188+
@SuppressWarnings("removal")
189+
@Deprecated(since = "7.0", forRemoval = true)
188190
public RequestEntity(@Nullable T body, @Nullable MultiValueMap<String, String> headers,
189191
@Nullable HttpMethod method, @Nullable URI url, @Nullable Type type) {
190192

spring-web/src/main/java/org/springframework/http/ResponseEntity.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ public ResponseEntity(@Nullable T body, @Nullable HttpHeaders headers, HttpStatu
139139
* Create a {@code ResponseEntity} with headers and a status code.
140140
* @param headers the entity headers
141141
* @param status the status code
142-
* @deprecated Use {@link #ResponseEntity(HttpHeaders, HttpStatusCode)}
142+
* @deprecated in favor of {@link #ResponseEntity(HttpHeaders, HttpStatusCode)}
143143
*/
144-
@Deprecated
144+
@Deprecated(since = "7.0", forRemoval = true)
145145
public ResponseEntity(MultiValueMap<String, String> headers, HttpStatusCode status) {
146146
this(null, headers, status);
147147
}
@@ -152,9 +152,9 @@ public ResponseEntity(MultiValueMap<String, String> headers, HttpStatusCode stat
152152
* @param headers the entity headers
153153
* @param rawStatus the status code value
154154
* @since 5.3.2
155-
* @deprecated Use {@link #ResponseEntity(Object, HttpHeaders, int)}
155+
* @deprecated in favor of {@link #ResponseEntity(Object, HttpHeaders, int)}
156156
*/
157-
@Deprecated
157+
@Deprecated(since = "7.0", forRemoval = true)
158158
public ResponseEntity(@Nullable T body, @Nullable MultiValueMap<String, String> headers, int rawStatus) {
159159
this(body, headers, HttpStatusCode.valueOf(rawStatus));
160160
}
@@ -164,9 +164,10 @@ public ResponseEntity(@Nullable T body, @Nullable MultiValueMap<String, String>
164164
* @param body the entity body
165165
* @param headers the entity headers
166166
* @param statusCode the status code
167-
* @deprecated Use {@link #ResponseEntity(Object, HttpHeaders, HttpStatusCode)}
167+
* @deprecated in favor of {@link #ResponseEntity(Object, HttpHeaders, HttpStatusCode)}
168168
*/
169-
@Deprecated
169+
@SuppressWarnings("removal")
170+
@Deprecated(since = "7.0", forRemoval = true)
170171
public ResponseEntity(@Nullable T body, @Nullable MultiValueMap<String, String> headers, HttpStatusCode statusCode) {
171172
super(body, headers);
172173
Assert.notNull(statusCode, "HttpStatusCode must not be null");

spring-web/src/main/java/org/springframework/web/cors/UrlBasedCorsConfigurationSource.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public UrlBasedCorsConfigurationSource(PathPatternParser parser) {
9393
* {@link #setUrlPathHelper(UrlPathHelper)}, if at all. For further details,
9494
* please see {@link #setAllowInitLookupPath(boolean)}.
9595
*/
96-
@Deprecated
96+
@Deprecated(since = "5.3", forRemoval = true)
9797
public void setAlwaysUseFullPath(boolean alwaysUseFullPath) {
9898
initUrlPathHelper();
9999
this.urlPathHelper.setAlwaysUseFullPath(alwaysUseFullPath);
@@ -107,7 +107,7 @@ public void setAlwaysUseFullPath(boolean alwaysUseFullPath) {
107107
* {@link #setUrlPathHelper(UrlPathHelper)}, if at all. For further details,
108108
* please see {@link #setAllowInitLookupPath(boolean)}.
109109
*/
110-
@Deprecated
110+
@Deprecated(since = "5.3", forRemoval = true)
111111
public void setUrlDecode(boolean urlDecode) {
112112
initUrlPathHelper();
113113
this.urlPathHelper.setUrlDecode(urlDecode);
@@ -121,7 +121,7 @@ public void setUrlDecode(boolean urlDecode) {
121121
* {@link #setUrlPathHelper(UrlPathHelper)}, if at all. For further details,
122122
* please see {@link #setAllowInitLookupPath(boolean)}.
123123
*/
124-
@Deprecated
124+
@Deprecated(since = "5.3", forRemoval = true)
125125
public void setRemoveSemicolonContent(boolean removeSemicolonContent) {
126126
initUrlPathHelper();
127127
this.urlPathHelper.setRemoveSemicolonContent(removeSemicolonContent);

spring-web/src/test/java/org/springframework/http/HttpEntityTests.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020

2121
import org.junit.jupiter.api.Test;
2222

23-
import org.springframework.util.LinkedMultiValueMap;
24-
import org.springframework.util.MultiValueMap;
25-
2623
import static org.assertj.core.api.Assertions.assertThat;
2724

2825
/**
@@ -51,11 +48,10 @@ void httpHeaders() {
5148

5249
@Test
5350
void multiValueMap() {
54-
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
55-
map.set("Content-Type", "text/plain");
51+
HttpHeaders headers = new HttpHeaders();
52+
headers.set("Content-Type", "text/plain");
5653
String body = "foo";
57-
@SuppressWarnings("deprecation")
58-
HttpEntity<String> entity = new HttpEntity<>(body, map);
54+
HttpEntity<String> entity = new HttpEntity<>(body, headers);
5955
assertThat(entity.getBody()).isEqualTo(body);
6056
assertThat(entity.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
6157
assertThat(entity.getHeaders().getFirst("Content-Type")).isEqualTo("text/plain");

spring-web/src/test/java/org/springframework/http/server/reactive/HeadersAdaptersTests.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,9 @@ void copyUsingEntrySetPutRemovesDuplicates(MultiValueMap<String, String> headers
133133
assertThat(headers2.get("TestHeader")).as("TestHeader")
134134
.containsExactly("first", "second", "third");
135135
// Ordering and casing are not guaranteed using the entrySet+put approach
136-
assertThat(headers2.asMultiValueMap()).as("two keys")
137-
.containsKey("testheader")
138-
.containsKey("secondheader")
139-
.hasSize(2);
136+
assertThat(headers2.containsHeader("testheader")).isTrue();
137+
assertThat(headers2.containsHeader("secondheader")).isTrue();
138+
assertThat(headers2.size()).isEqualTo(2);
140139
assertThat(headers2.toString()).as("no 'with native headers' dump")
141140
.doesNotContain("with native headers");
142141
}
@@ -150,10 +149,9 @@ void copyUsingPutAllRemovesDuplicates(MultiValueMap<String, String> headers) {
150149
assertThat(headers2.get("TestHeader")).as("TestHeader")
151150
.containsExactly("first", "second", "third");
152151
// Ordering and casing are not guaranteed using the putAll approach
153-
assertThat(headers2.asMultiValueMap()).as("two keys")
154-
.containsKey("testheader")
155-
.containsKey("secondheader")
156-
.hasSize(2);
152+
assertThat(headers2.containsHeader("testheader")).isTrue();
153+
assertThat(headers2.containsHeader("secondheader")).isTrue();
154+
assertThat(headers2.size()).isEqualTo(2);
157155
assertThat(headers2.toString()).as("similar toString, no 'with native headers' dump")
158156
.isEqualToIgnoringCase(headers.toString().substring(0, headers.toString().indexOf(']') + 1));
159157
}

spring-web/src/test/java/org/springframework/web/ErrorResponseTests.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@
1616

1717
package org.springframework.web;
1818

19-
import java.util.List;
20-
2119
import org.junit.jupiter.api.Test;
2220

2321
import org.springframework.http.HttpStatus;
2422

25-
import static java.util.Map.entry;
2623
import static org.assertj.core.api.Assertions.assertThat;
2724

2825
/**
@@ -33,24 +30,24 @@
3330
class ErrorResponseTests {
3431

3532
@Test
36-
@SuppressWarnings("deprecation")
3733
void createWithHttpHeader() {
38-
ErrorResponse response = ErrorResponse.builder(new IllegalStateException(), HttpStatus.BAD_REQUEST, "test")
39-
.header("header", "value").build();
40-
assertThat(response.getHeaders().asMultiValueMap()).containsOnly(entry("header", List.of("value")));
34+
ErrorResponse response = ErrorResponse
35+
.builder(new IllegalStateException(), HttpStatus.BAD_REQUEST, "test")
36+
.header("header", "value")
37+
.build();
38+
assertThat(response.getHeaders().containsHeaderValue("header", "value")).isTrue();
4139
}
4240

4341
@Test
44-
@SuppressWarnings("deprecation")
4542
void createWithHttpHeadersConsumer() {
4643
ErrorResponse response = ErrorResponse.builder(new IllegalStateException(), HttpStatus.BAD_REQUEST, "test")
4744
.header("header", "value")
4845
.headers(headers -> {
4946
headers.add("header", "value2");
5047
headers.add("another", "value3");
5148
}).build();
52-
assertThat(response.getHeaders().asMultiValueMap()).containsOnly(entry("header", List.of("value", "value2")),
53-
entry("another", List.of("value3")));
49+
assertThat(response.getHeaders().get("header")).containsExactly("value", "value2");
50+
assertThat(response.getHeaders().get("another")).containsExactly("value3");
5451
}
5552

5653
}

spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpRequest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,9 @@ public interface BaseBuilder<B extends BaseBuilder<B>> {
282282
/**
283283
* Add the given header values.
284284
* @param headers the header values
285-
* @deprecated Use {@link #headers(HttpHeaders)}
285+
* @deprecated in favor of {@link #headers(HttpHeaders)}
286286
*/
287-
@Deprecated
287+
@Deprecated(since = "7.0", forRemoval = true)
288288
B headers(MultiValueMap<String, String> headers);
289289

290290
/**
@@ -483,7 +483,7 @@ public BodyBuilder header(String headerName, String... headerValues) {
483483
}
484484

485485
@Override
486-
@Deprecated
486+
@Deprecated(since = "7.0", forRemoval = true)
487487
public BodyBuilder headers(MultiValueMap<String, String> headers) {
488488
this.headers.putAll(headers);
489489
return this;

0 commit comments

Comments
 (0)