[JENKINS-43531] Plugins may not be expecting InvalidPathException

- Plugins should really be expecting it, but as historically they have not, may as well convert to IOE for them
This commit is contained in:
Stephen Connolly committed 2017-04-19 14:04:33 +01:00
1 parent 33942677d4
commit 3871d7778e
31 files changed
+209 -46

No files matched your search

+17 -10
View File
@@ -34,6 +34,7 @@ import hudson.model.Descriptor;
import hudson.util.AtomicFileWriter;
import hudson.util.XStream2;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
@@ -140,7 +141,7 @@ public final class XmlFile {
}
try (InputStream in = new BufferedInputStream(Files.newInputStream(file.toPath()))) {
return xs.fromXML(in);
} catch (XStreamException | Error e) {
} catch (XStreamException | Error | InvalidPathException e) {
throw new IOException("Unable to read "+file,e);
}
}
@@ -157,7 +158,7 @@ public final class XmlFile {
try (InputStream in = new BufferedInputStream(Files.newInputStream(file.toPath()))) {
// TODO: expose XStream the driver from XStream
return xs.unmarshal(DEFAULT_DRIVER.createReader(in), o);
} catch (XStreamException | Error e) {
} catch (XStreamException | Error | InvalidPathException e) {
throw new IOException("Unable to read "+file,e);
}
}
@@ -201,14 +202,18 @@ public final class XmlFile {
* @return Reader for the file. should be close externally once read.
*/
public Reader readRaw() throws IOException {
InputStream fileInputStream = Files.newInputStream(file.toPath());
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;
InputStream fileInputStream = Files.newInputStream(file.toPath());
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;
}
} catch (InvalidPathException e) {
throw new IOException(e);
}
}
@@ -288,7 +293,9 @@ public final class XmlFile {
// in such a case, assume UTF-8 rather than fail, since Jenkins internally always write XML in UTF-8
return "UTF-8";
} catch (SAXException e) {
throw new IOException("Failed to detect encoding of "+file,e);
throw new IOException("Failed to detect encoding of " + file, e);
} catch (InvalidPathException e) {
throw new IOException(e);
} catch (ParserConfigurationException e) {
throw new AssertionError(e); // impossible
}