diff --git a/flow-server/src/main/java/com/vaadin/flow/router/RouteNotFoundError.java b/flow-server/src/main/java/com/vaadin/flow/router/RouteNotFoundError.java index 6e8bb47fa26..b3d18d74334 100644 --- a/flow-server/src/main/java/com/vaadin/flow/router/RouteNotFoundError.java +++ b/flow-server/src/main/java/com/vaadin/flow/router/RouteNotFoundError.java @@ -18,6 +18,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.List; import java.util.stream.Collectors; @@ -93,10 +94,9 @@ private static String getErrorHtml(boolean productionMode) { } private static String readHtmlFile(String templateName) { - try { - return IOUtils.toString( - RouteNotFoundError.class.getResourceAsStream(templateName), - StandardCharsets.UTF_8); + try (InputStream stream = RouteNotFoundError.class + .getResourceAsStream(templateName)) { + return IOUtils.toString(stream, StandardCharsets.UTF_8); } catch (IOException e) { getLogger().error("Unable to read " + templateName, e); // Use a very simple error page if the real one could not be found