Skip to content

Commit 89ba0fd

Browse files
committed
Polishing contribution
Closes gh-35294
1 parent 96deb27 commit 89ba0fd

File tree

10 files changed

+16
-26
lines changed

10 files changed

+16
-26
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ protected ProblemDetail() {
102102

103103
/**
104104
* Setter for the {@link #getType() problem type}.
105-
* <p>By default, this is not set. According to the spec, when not present, its value is assumed to be "about:blank"
105+
* <p>By default, this is not set. According to the spec, when not present,
106+
* the type is assumed to be "about:blank"
106107
* @param type the problem type
107108
*/
108109
public void setType(@Nullable URI type) {

spring-web/src/main/java/org/springframework/web/DefaultErrorResponseBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private HttpHeaders getHeaders() {
8585
}
8686

8787
@Override
88-
public ErrorResponse.Builder type(URI type) {
88+
public ErrorResponse.Builder type(@Nullable URI type) {
8989
this.problemDetail.setType(type);
9090
return this;
9191
}

spring-web/src/main/java/org/springframework/web/ErrorResponseException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public HttpHeaders getHeaders() {
111111
* Set the {@link ProblemDetail#setType(URI) type} field of the response body.
112112
* @param type the problem type
113113
*/
114-
public void setType(URI type) {
114+
public void setType(@Nullable URI type) {
115115
this.body.setType(type);
116116
}
117117

spring-web/src/test/java/org/springframework/http/converter/json/ProblemDetailJacksonMixinTests.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,25 @@ class ProblemDetailJacksonMixinTests {
4242

4343

4444
@Test
45-
void writeStatusAndHeaders() throws Exception {
45+
void writeStatusAndHeaders() {
4646
ProblemDetail detail = ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST, "Missing header");
4747
testWrite(detail,
4848
"""
4949
{
50-
"type": "about:blank",
5150
"title": "Bad Request",
5251
"status": 400,
5352
"detail": "Missing header"
5453
}""");
5554
}
5655

5756
@Test
58-
void writeCustomProperty() throws Exception {
57+
void writeCustomProperty() {
5958
ProblemDetail detail = ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST, "Missing header");
6059
detail.setProperty("host", "abc.org");
6160
detail.setProperty("user", null);
6261

6362
testWrite(detail, """
6463
{
65-
"type": "about:blank",
6664
"title": "Bad Request",
6765
"status": 400,
6866
"detail": "Missing header",
@@ -72,7 +70,7 @@ void writeCustomProperty() throws Exception {
7270
}
7371

7472
@Test
75-
void readCustomProperty() throws Exception {
73+
void readCustomProperty() {
7674
ProblemDetail detail = this.mapper.readValue("""
7775
{
7876
"type": "about:blank",
@@ -93,7 +91,7 @@ void readCustomProperty() throws Exception {
9391
}
9492

9593
@Test
96-
void readCustomPropertyFromXml() throws Exception {
94+
void readCustomPropertyFromXml() {
9795
ObjectMapper xmlMapper = XmlMapper.builder().addMixIn(ProblemDetail.class, ProblemDetailJacksonMixin.class).build();
9896
ProblemDetail detail = xmlMapper.readValue("""
9997
<problem xmlns="urn:ietf:rfc:7807">
@@ -111,7 +109,7 @@ void readCustomPropertyFromXml() throws Exception {
111109
assertThat(detail.getProperties()).containsEntry("host", "abc.org");
112110
}
113111

114-
private void testWrite(ProblemDetail problemDetail, String expected) throws Exception {
112+
private void testWrite(ProblemDetail problemDetail, String expected) {
115113
String output = this.mapper.writeValueAsString(problemDetail);
116114
JSONAssert.assertEquals(expected, output, false);
117115
}

spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerErrorTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ void noStaticResource() {
125125
"detail":"No static resource non-existing.",\
126126
"instance":"\\/resources\\/non-existing",\
127127
"status":404,\
128-
"title":"Not Found",\
129-
"type":"about:blank"}\
128+
"title":"Not Found"}\
130129
""");
131130
}
132131

spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingExceptionHandlingIntegrationTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ void globalExceptionHandlerWithHandlerNotFound() throws Exception {
125125
assertThat(ex.getResponseBodyAsString()).isEqualTo("{" +
126126
"\"instance\":\"\\/no-such-handler\"," +
127127
"\"status\":404," +
128-
"\"title\":\"Not Found\"," +
129-
"\"type\":\"about:blank\"}");
128+
"\"title\":\"Not Found\"}");
130129
});
131130
}
132131

@@ -142,8 +141,7 @@ void globalExceptionHandlerWithMissingRequestParameter() throws Exception {
142141
"\"detail\":\"Required query parameter 'q' is not present.\"," +
143142
"\"instance\":\"\\/missing-request-parameter\"," +
144143
"\"status\":400," +
145-
"\"title\":\"Bad Request\"," +
146-
"\"type\":\"about:blank\"}");
144+
"\"title\":\"Bad Request\"}");
147145
});
148146
}
149147

spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseBodyResultHandlerTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ private void testProblemDetailMediaType(MockServerWebExchange exchange, MediaTyp
152152
{\
153153
"status":400,\
154154
"instance":"\\/path",\
155-
"title":"Bad Request",\
156-
"type":"about:blank"\
155+
"title":"Bad Request"\
157156
}""");
158157
}
159158

spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandlerTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,7 @@ void handleErrorResponse() {
244244
{\
245245
"instance":"\\/path",\
246246
"status":400,\
247-
"title":"Bad Request",\
248-
"type":"about:blank"\
247+
"title":"Bad Request"\
249248
}""");
250249
}
251250

@@ -265,8 +264,7 @@ void handleProblemDetail() {
265264
{\
266265
"instance":"\\/path",\
267266
"status":400,\
268-
"title":"Bad Request",\
269-
"type":"about:blank"\
267+
"title":"Bad Request"\
270268
}""");
271269
}
272270

spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorTests.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,15 +395,13 @@ private void testProblemDetailMediaType(String expectedContentType) throws Excep
395395
<status>400</status>
396396
<instance>/path</instance>
397397
<title>Bad Request</title>
398-
<type>about:blank</type>
399398
</problem>""")
400399
.ignoreWhitespace()
401400
.areIdentical();
402401
}
403402
else {
404403
JSONAssert.assertEquals("""
405404
{
406-
"type": "about:blank",
407405
"title": "Bad Request",
408406
"status": 400,
409407
"instance": "/path"

spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerIntegrationTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ void testNoResourceFoundException() throws Exception {
144144
"detail":"No static resource non-existing.",\
145145
"instance":"\\/cp\\/non-existing",\
146146
"status":404,\
147-
"title":"Not Found",\
148-
"type":"about:blank"\
147+
"title":"Not Found"\
149148
}\
150149
""");
151150
}

0 commit comments

Comments
 (0)