From c438f6411488a8ebe795fd67c52456cb7e9e972a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 9 Jun 2016 07:20:54 +0200 Subject: [PATCH] Handle missing files correctly --- src/main/java/net/pterodactylus/sone/web/ReloadingPage.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/ReloadingPage.java b/src/main/java/net/pterodactylus/sone/web/ReloadingPage.java index 0c8f516..58c2d44 100644 --- a/src/main/java/net/pterodactylus/sone/web/ReloadingPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ReloadingPage.java @@ -19,6 +19,7 @@ package net.pterodactylus.sone.web; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -72,8 +73,10 @@ public class ReloadingPage implements Page { String path = request.getUri().getPath(); int lastSlash = path.lastIndexOf('/'); String filename = path.substring(lastSlash + 1); - InputStream fileInputStream = new FileInputStream(new File(filesystemPath, filename)); - if (fileInputStream == null) { + InputStream fileInputStream; + try { + fileInputStream = new FileInputStream(new File(filesystemPath, filename)); + } catch (FileNotFoundException fnfe1) { return response.setStatusCode(404).setStatusText("Not found."); } OutputStream contentOutputStream = response.getContent(); -- 2.7.4