From e603b100889efb71cc71949dc9df7d8eeae5256a Mon Sep 17 00:00:00 2001 From: Stephen Connolly Date: Tue, 21 Mar 2017 13:55:06 +0000 Subject: [PATCH] [JENKINS-42934] A couple of places where FileNotFoundException may be replaced by NoSuchFileException by JVM shenanigans --- core/src/main/java/hudson/cli/BuildCommand.java | 3 ++- .../main/java/hudson/util/io/ReopenableFileOutputStream.java | 3 ++- core/src/test/java/jenkins/util/VirtualFileTest.java | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/hudson/cli/BuildCommand.java b/core/src/main/java/hudson/cli/BuildCommand.java index 1b96e15733..9fb72d74cc 100644 --- a/core/src/main/java/hudson/cli/BuildCommand.java +++ b/core/src/main/java/hudson/cli/BuildCommand.java @@ -44,6 +44,7 @@ import hudson.model.queue.QueueTaskFuture; import hudson.util.EditDistance; import hudson.util.StreamTaskListener; +import java.nio.file.NoSuchFileException; import jenkins.scm.SCMDecisionHandler; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.CmdLineException; @@ -189,7 +190,7 @@ public class BuildCommand extends CLICommand { b.writeWholeLogTo(stdout); break; } - catch (FileNotFoundException e) { + catch (FileNotFoundException | NoSuchFileException e) { if ( i == retryCnt ) { Exception myException = new AbortException(); myException.initCause(e); diff --git a/core/src/main/java/hudson/util/io/ReopenableFileOutputStream.java b/core/src/main/java/hudson/util/io/ReopenableFileOutputStream.java index 9881f7c0d7..ccc8ba6a42 100644 --- a/core/src/main/java/hudson/util/io/ReopenableFileOutputStream.java +++ b/core/src/main/java/hudson/util/io/ReopenableFileOutputStream.java @@ -29,6 +29,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.nio.file.Files; +import java.nio.file.NoSuchFileException; import java.nio.file.StandardOpenOption; /** @@ -56,7 +57,7 @@ import java.nio.file.StandardOpenOption; try { current = Files.newOutputStream(out.toPath(), StandardOpenOption.CREATE, appendOnNextOpen ? StandardOpenOption.APPEND : StandardOpenOption.TRUNCATE_EXISTING); - } catch (FileNotFoundException e) { + } catch (FileNotFoundException | NoSuchFileException e) { throw new IOException("Failed to open "+out,e); } return current; diff --git a/core/src/test/java/jenkins/util/VirtualFileTest.java b/core/src/test/java/jenkins/util/VirtualFileTest.java index c45f45109c..1d0b8457f5 100644 --- a/core/src/test/java/jenkins/util/VirtualFileTest.java +++ b/core/src/test/java/jenkins/util/VirtualFileTest.java @@ -29,6 +29,7 @@ import hudson.Util; import hudson.model.TaskListener; import java.io.File; import java.io.FileNotFoundException; +import java.nio.file.NoSuchFileException; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.junit.Test; @@ -63,9 +64,9 @@ public class VirtualFileTest { try { hack.open(); fail(); - } catch (FileNotFoundException x) { + } catch (FileNotFoundException | NoSuchFileException x) { // OK } } -} \ No newline at end of file +}