Skip to content

Commit 395c1e4

Browse files
committed
Polishing contribution
See gh-24074
1 parent a15a726 commit 395c1e4

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -124,16 +124,16 @@ public String getMultipartContentType(String paramOrFileName) {
124124
if (file != null) {
125125
return file.getContentType();
126126
}
127-
128127
try {
129128
Part part = getPart(paramOrFileName);
130129
if (part != null) {
131130
return part.getContentType();
132131
}
133-
} catch (ServletException | IOException e) {
134-
throw new IllegalStateException("Cannot extract content type from multipart request.", e);
135132
}
136-
133+
catch (ServletException | IOException ex) {
134+
// Should never happen (we're not actually parsing)
135+
throw new IllegalStateException(ex);
136+
}
137137
return null;
138138
}
139139

spring-web/src/test/java/org/springframework/mock/web/test/MockMultipartHttpServletRequest.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,13 +16,16 @@
1616

1717
package org.springframework.mock.web.test;
1818

19+
import java.io.IOException;
1920
import java.util.Collections;
2021
import java.util.Enumeration;
2122
import java.util.Iterator;
2223
import java.util.List;
2324
import java.util.Map;
2425

2526
import javax.servlet.ServletContext;
27+
import javax.servlet.ServletException;
28+
import javax.servlet.http.Part;
2629

2730
import org.springframework.http.HttpHeaders;
2831
import org.springframework.http.HttpMethod;
@@ -121,9 +124,17 @@ public String getMultipartContentType(String paramOrFileName) {
121124
if (file != null) {
122125
return file.getContentType();
123126
}
124-
else {
125-
return null;
127+
try {
128+
Part part = getPart(paramOrFileName);
129+
if (part != null) {
130+
return part.getContentType();
131+
}
132+
}
133+
catch (ServletException | IOException ex) {
134+
// Should never happen (we're not actually parsing)
135+
throw new IllegalStateException(ex);
126136
}
137+
return null;
127138
}
128139

129140
@Override

0 commit comments

Comments
 (0)