From 1b852e305230f165a8d8be17d72b5a6ad745bf7f Mon Sep 17 00:00:00 2001 From: Artur Date: Tue, 2 Nov 2021 14:32:58 +0200 Subject: [PATCH] chore: Close input stream after using it (#12235) Fixes #9363 --- .../java/com/vaadin/flow/router/RouteNotFoundError.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 9e8d6360e67..faf00cb275f 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; @@ -86,10 +87,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);