Skip to content

Commit 0d0192d

Browse files
author
ntwigg
committed
Use try-with-resources to make sure we don't have dangling streams.
1 parent b12ff7c commit 0d0192d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/src/main/java/com/diffplug/spotless/FormatterProperties.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,17 @@ protected Properties executeXmlContent(String content) throws IOException, Illeg
185185
}
186186

187187
private Properties executeWithSupplier(Supplier<InputStream> isSupplier) throws IOException, IllegalArgumentException {
188-
Node rootNode = getRootNode(isSupplier.get());
189-
String nodeName = rootNode.getNodeName();
190-
if (null == nodeName) {
191-
throw new IllegalArgumentException("XML document does not contain a root node.");
188+
Node rootNode;
189+
try (InputStream input = isSupplier.get()) {
190+
rootNode = getRootNode(input);
191+
String nodeName = rootNode.getNodeName();
192+
if (null == nodeName) {
193+
throw new IllegalArgumentException("XML document does not contain a root node.");
194+
}
195+
}
196+
try (InputStream input = isSupplier.get()) {
197+
return XmlParser.parse(input, rootNode);
192198
}
193-
return XmlParser.parse(isSupplier.get(), rootNode);
194199
}
195200

196201
private Node getRootNode(final InputStream is) throws IOException, IllegalArgumentException {

0 commit comments

Comments
 (0)