Skip to content

Commit ec5d81e

Browse files
committed
Ensure method & requestURI are non-null in MHSR
Prior to this commit it was possible for the method and requestURI fields in MockHttpServletRequest to be set to null. This commit ensures that the method and requestURI fields are internally stored as empty strings if the user sets them to a null value. Issue: SPR-10643
1 parent 86591e5 commit ec5d81e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

spring-test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ public MockHttpServletRequest(ServletContext servletContext) {
249249
*/
250250
public MockHttpServletRequest(ServletContext servletContext, String method, String requestURI) {
251251
this.servletContext = (servletContext != null ? servletContext : new MockServletContext());
252-
this.method = method;
253-
this.requestURI = requestURI;
252+
this.method = (method == null ? "" : method);
253+
this.requestURI = (requestURI == null ? "" : requestURI);
254254
this.locales.add(Locale.ENGLISH);
255255
}
256256

@@ -859,7 +859,7 @@ else if (value != null) {
859859
}
860860

861861
public void setMethod(String method) {
862-
this.method = method;
862+
this.method = (method == null ? "" : method);
863863
}
864864

865865
@Override
@@ -937,7 +937,7 @@ public String getRequestedSessionId() {
937937
}
938938

939939
public void setRequestURI(String requestURI) {
940-
this.requestURI = requestURI;
940+
this.requestURI = (requestURI == null ? "" : requestURI);
941941
}
942942

943943
@Override

0 commit comments

Comments
 (0)