From 6d909b013e17e18da13f00213254a784c19408e4 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Tue, 30 Jan 2018 16:15:04 -0500 Subject: [PATCH] Do not commit response on access to content MockHttpServletResponse no longer calls flushBuffer on calls to getContentAsByteArray and getContentAsString. The flushing doesn't actually do anything useful but does commit the response leading to unexpected side effects. Issue: SPR-16430 --- .../org/springframework/mock/web/MockHttpServletResponse.java | 4 +--- .../mock/web/test/MockHttpServletResponse.java | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java b/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java index 75720f2e3a..6ba3f2cfc3 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -199,12 +199,10 @@ public class MockHttpServletResponse implements HttpServletResponse { } public byte[] getContentAsByteArray() { - flushBuffer(); return this.content.toByteArray(); } public String getContentAsString() throws UnsupportedEncodingException { - flushBuffer(); return (this.characterEncoding != null ? this.content.toString(this.characterEncoding) : this.content.toString()); } diff --git a/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletResponse.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletResponse.java index 0f555dfb67..cd8a3909bb 100644 --- a/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletResponse.java +++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -192,12 +192,10 @@ public class MockHttpServletResponse implements HttpServletResponse { } public byte[] getContentAsByteArray() { - flushBuffer(); return this.content.toByteArray(); } public String getContentAsString() throws UnsupportedEncodingException { - flushBuffer(); return (this.characterEncoding != null ? this.content.toString(this.characterEncoding) : this.content.toString()); }