diff --git a/core/src/main/java/hudson/XmlFile.java b/core/src/main/java/hudson/XmlFile.java index 933621b74b..9f438eeded 100644 --- a/core/src/main/java/hudson/XmlFile.java +++ b/core/src/main/java/hudson/XmlFile.java @@ -51,6 +51,7 @@ import java.io.InputStreamReader; import java.io.Reader; import java.io.Writer; import java.io.StringWriter; +import java.io.UnsupportedEncodingException; import java.util.logging.Level; import java.util.logging.Logger; @@ -196,9 +197,19 @@ public final class XmlFile { * Opens a {@link Reader} that loads XML. * This method uses {@link #sniffEncoding() the right encoding}, * not just the system default encoding. + * @throws IOException Encoding issues + * @return Reader for the file. should be close externally once read. */ public Reader readRaw() throws IOException { - return new InputStreamReader(new FileInputStream(file),sniffEncoding()); + FileInputStream fileInputStream = new FileInputStream(file); + try { + return new InputStreamReader(fileInputStream, sniffEncoding()); + } catch(IOException ex) { + // Exception may happen if we fail to find encoding or if this encoding is unsupported. + // In such case we close the underlying stream and rethrow. + Util.closeAndLogFailures(fileInputStream, LOGGER, "FileInputStream", file.toString()); + throw ex; + } } /**