File tree 3 files changed +22
-3
lines changed
main/java/org/springframework/web/client
test/java/org/springframework
3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -79,8 +79,13 @@ public boolean hasMessageBody() throws IOException {
79
79
* @return {@code true} if the response has a zero-length message body, {@code false} otherwise
80
80
* @throws IOException in case of I/O errors
81
81
*/
82
+ @ SuppressWarnings ("ConstantConditions" )
82
83
public boolean hasEmptyMessageBody () throws IOException {
83
84
InputStream body = this .response .getBody ();
85
+ // Per contract body shouldn't be null, but check anyway..
86
+ if (body == null ) {
87
+ return true ;
88
+ }
84
89
if (body .markSupported ()) {
85
90
body .mark (1 );
86
91
if (body .read () == -1 ) {
Original file line number Diff line number Diff line change @@ -175,7 +175,7 @@ public void invalidData() {
175
175
.verifyError (DecodingException .class ));
176
176
}
177
177
178
- @ Test // # 22042
178
+ @ Test // gh- 22042
179
179
public void decodeWithNullLiteral () {
180
180
Flux <Object > result = this .decoder .decode (Flux .concat (stringBuffer ("null" )),
181
181
ResolvableType .forType (Pojo .class ), MediaType .APPLICATION_JSON , Collections .emptyMap ());
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -113,6 +113,20 @@ public void emptyMessageBody() throws IOException {
113
113
assertNull (result );
114
114
}
115
115
116
+ @ Test // gh-22265
117
+ @ SuppressWarnings ("unchecked" )
118
+ public void nullMessageBody () throws IOException {
119
+ HttpMessageConverter <String > converter = mock (HttpMessageConverter .class );
120
+ HttpHeaders responseHeaders = new HttpHeaders ();
121
+ extractor = new HttpMessageConverterExtractor <>(String .class , createConverterList (converter ));
122
+ given (response .getRawStatusCode ()).willReturn (HttpStatus .OK .value ());
123
+ given (response .getHeaders ()).willReturn (responseHeaders );
124
+ given (response .getBody ()).willReturn (null );
125
+
126
+ Object result = extractor .extractData (response );
127
+ assertNull (result );
128
+ }
129
+
116
130
@ Test
117
131
@ SuppressWarnings ("unchecked" )
118
132
public void normal () throws IOException {
You can’t perform that action at this time.
0 commit comments