From f64a309df5777ae936cb1df876a94c43af729348 Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Fri, 5 Apr 2024 21:39:23 -0400 Subject: [PATCH] [cleanup] Use try with resources to ensure reader is closed --- .../revelc/code/formatter/xml/lib/XmlDocumentFormatter.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/net/revelc/code/formatter/xml/lib/XmlDocumentFormatter.java b/src/main/java/net/revelc/code/formatter/xml/lib/XmlDocumentFormatter.java index 5dbf4d9..f27ba77 100644 --- a/src/main/java/net/revelc/code/formatter/xml/lib/XmlDocumentFormatter.java +++ b/src/main/java/net/revelc/code/formatter/xml/lib/XmlDocumentFormatter.java @@ -97,10 +97,9 @@ public String format(String documentText) { validateWellFormedness(documentText); } - Reader reader = new StringReader(documentText); FormatState state = new FormatState(); - try { + try (Reader reader = new StringReader(documentText)) { while (true) { reader.mark(1); int intChar = reader.read(); @@ -111,7 +110,6 @@ public String format(String documentText) { } copyNode(reader, state); } - reader.close(); } catch (IOException e) { logger.error("{}", e.getMessage()); logger.debug("", e);