Fix NPE in OnCommittedResponseWrapper trackContentLength (#3824)
OnCommittedResponseWrapper trackContentLength will throw a NullPointerException when the content length passed in is null. This commit properly tracks the null value as a length of 4. Fixes gh-3823
This commit is contained in:
@@ -545,6 +545,21 @@ public class OnCommittedResponseWrapperTests {
|
||||
// The amount of content specified in the setContentLength method of the response
|
||||
// has been greater than zero and has been written to the response.
|
||||
|
||||
// gh-3823
|
||||
@Test
|
||||
public void contentLengthPrintWriterWriteNullCommits() throws Exception {
|
||||
String expected = null;
|
||||
this.response.setContentLength(String.valueOf(expected).length() + 1);
|
||||
|
||||
this.response.getWriter().write(expected);
|
||||
|
||||
assertThat(this.committed).isFalse();
|
||||
|
||||
this.response.getWriter().write("a");
|
||||
|
||||
assertThat(this.committed).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentLengthPrintWriterWriteIntCommits() throws Exception {
|
||||
int expected = 1;
|
||||
|
||||
Reference in New Issue
Block a user