aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2014-12-10 23:41:45 +0200
committerVaadin Code Review <review@vaadin.com>2014-12-11 11:38:06 +0000
commit4e477009c14231b5ecbd6bd0d289ac88eace2391 (patch)
treecf026e9952875f828a0095104ccc6e20f611577f
parentc0f689891ca05e9e74d184ee7528e1aadde84023 (diff)
downloadvaadin-framework-4e477009c14231b5ecbd6bd0d289ac88eace2391.tar.gz
vaadin-framework-4e477009c14231b5ecbd6bd0d289ac88eace2391.zip
Validate input to FileResource constructor (#14253)
Change-Id: I7789f2de4cb179dfff936498f58dd6f2e491689b
-rw-r--r--server/src/com/vaadin/server/FileResource.java3
-rw-r--r--server/tests/src/com/vaadin/tests/server/FileResourceTest.java36
2 files changed, 39 insertions, 0 deletions
diff --git a/server/src/com/vaadin/server/FileResource.java b/server/src/com/vaadin/server/FileResource.java
index de14e2f0f2..b32905f972 100644
--- a/server/src/com/vaadin/server/FileResource.java
+++ b/server/src/com/vaadin/server/FileResource.java
@@ -57,6 +57,9 @@ public class FileResource implements ConnectorResource {
* the file that should be served.
*/
public FileResource(File sourceFile) {
+ if (sourceFile == null) {
+ throw new IllegalArgumentException("File cannot be null");
+ }
setSourceFile(sourceFile);
}
diff --git a/server/tests/src/com/vaadin/tests/server/FileResourceTest.java b/server/tests/src/com/vaadin/tests/server/FileResourceTest.java
new file mode 100644
index 0000000000..4798fb9f05
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/FileResourceTest.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.server;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import com.vaadin.server.FileResource;
+
+public class FileResourceTest {
+
+ @Test(expected = IllegalArgumentException.class)
+ public void nullFile() {
+ new FileResource(null);
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void nonExistingFile() {
+ new FileResource(new File("nonexisting")).getStream();
+ }
+
+}