Copilot commented on code in PR #637:
URL: https://github.com/apache/maven-war-plugin/pull/637#discussion_r3650842096
##########
src/main/java/org/apache/maven/plugins/war/packaging/AbstractWarPackagingTask.java:
##########
@@ -360,7 +360,7 @@ protected boolean copyFile(
* @throws java.io.IOException if an error occurred while reading the file
*/
protected String getEncoding(File webXml) throws IOException {
- try (XmlStreamReader xmlReader = new XmlStreamReader(webXml)) {
+ try (XmlStreamReader xmlReader = new
XmlStreamReader(Files.newInputStream(webXml.toPath()))) {
return xmlReader.getEncoding();
}
}
Review Comment:
`Files.newInputStream(...)` is created inside the `XmlStreamReader(...)`
constructor call. If the `XmlStreamReader(InputStream)` constructor throws
after opening the stream (e.g., while probing the XML prolog), the
`InputStream` will not be closed because the try-with-resources is never
entered, causing a potential file descriptor leak. Open the `InputStream` as
its own try-with-resources resource and then wrap it in `XmlStreamReader`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]