]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9488 do not fail when reading file part fails
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 10 Jul 2017 14:15:19 +0000 (16:15 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 21 Jul 2017 10:20:52 +0000 (12:20 +0200)
server/sonar-server/src/main/java/org/sonar/server/ws/ServletRequest.java
server/sonar-server/src/test/java/org/sonar/server/ws/ServletRequestTest.java

index 5308d825f1c3ab6c818b26447e1a3b65470c9da0..5c0afa73a145bd668335fd90f541302edf83af03 100644 (file)
@@ -29,6 +29,7 @@ import javax.annotation.CheckForNull;
 import javax.servlet.http.HttpServletRequest;
 import org.sonar.api.server.ws.internal.PartImpl;
 import org.sonar.api.server.ws.internal.ValidatingRequest;
+import org.sonar.api.utils.log.Loggers;
 import org.sonarqube.ws.MediaTypes;
 
 import static com.google.common.base.MoreObjects.firstNonNull;
@@ -99,7 +100,8 @@ public class ServletRequest extends ValidatingRequest {
       }
       return new PartImpl(part.getInputStream(), part.getSubmittedFileName());
     } catch (Exception e) {
-      throw new IllegalStateException("Can't read file part", e);
+      Loggers.get(ServletRequest.class).warn("Can't read file part for parameter " + key, e);
+      return null;
     }
   }
 
index 429ddcd8a25058f79cfe6e3d8e4123d17eb41f49..4fc4a5c8c082c38d1ed31ebcbe65951f102aed2b 100644 (file)
@@ -156,7 +156,7 @@ public class ServletRequestTest {
   }
 
   @Test
-  public void throw_ISE_when_invalid_part() throws Exception {
+  public void returns_null_when_invalid_part() throws Exception {
     when(source.getContentType()).thenReturn("multipart/form-data");
     InputStream file = mock(InputStream.class);
     Part part = mock(Part.class);
@@ -164,10 +164,7 @@ public class ServletRequestTest {
     when(part.getInputStream()).thenReturn(file);
     doThrow(IllegalArgumentException.class).when(source).getPart("param1");
 
-    expectedException.expect(IllegalStateException.class);
-    expectedException.expectMessage("Can't read file part");
-
-    underTest.readInputStreamParam("param1");
+    assertThat(underTest.readInputStreamParam("param1")).isNull();
   }
 
   @Test