diff --git a/cps/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsThreadGroup.java b/cps/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsThreadGroup.java
index 76de4f95d..65e441410 100644
--- a/cps/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsThreadGroup.java
+++ b/cps/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsThreadGroup.java
@@ -40,6 +40,8 @@
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
import java.util.HashMap;
import java.util.Map;
import java.util.NavigableMap;
@@ -55,6 +57,7 @@
import java.util.logging.Logger;
import static java.util.logging.Level.*;
+import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
import static org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.*;
import static org.jenkinsci.plugins.workflow.cps.persistence.PersistenceContext.*;
@@ -345,9 +348,14 @@ public void saveProgram(File f) throws IOException {
} finally {
w.close();
}
- Util.deleteFile(f);
- if (!tmpFile.renameTo(f)) {
- throw new IOException("rename " + tmpFile + " to " + f + " failed");
+ try {
+ Class.forName("java.nio.file.Files");
+ rename(tmpFile, f);
+ } catch (ClassNotFoundException x) { // Java 6
+ Util.deleteFile(f);
+ if (!tmpFile.renameTo(f)) {
+ throw new IOException("rename " + tmpFile + " to " + f + " failed");
+ }
}
LOGGER.log(FINE, "program state saved");
} catch (RuntimeException e) {
@@ -363,6 +371,10 @@ public void saveProgram(File f) throws IOException {
Util.deleteFile(tmpFile);
}
}
+ @IgnoreJRERequirement
+ private static void rename(File from, File to) throws IOException {
+ Files.move(from.toPath(), to.toPath(), StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
+ }
/**
* Propagates the failure to the workflow by passing an exception
diff --git a/pom.xml b/pom.xml
index 5b62b5c0d..db78bcbb9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -137,6 +137,25 @@
1.6
+
+ org.codehaus.mojo
+ animal-sniffer-maven-plugin
+ 1.13
+
+
+
+ check
+
+ check
+
+
+
+
+ org.codehaus.mojo.signature
+ java16
+
+
+