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 bc3be06e248..2031b815d2e 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; @@ -84,10 +85,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) { LoggerFactory.getLogger(RouteNotFoundError.class) .error("Unable to read " + templateName, e);