8004042: Arrrghs.java test failed on windows with access error.
Reviewed-by: smarks, jjh, ksrini
Contributed-by: david.dehaven@oracle.com
--- a/jdk/test/tools/launcher/Arrrghs.java Thu Dec 06 21:55:55 2012 -0800
+++ b/jdk/test/tools/launcher/Arrrghs.java Sun Dec 09 07:43:12 2012 -0800
@@ -27,7 +27,7 @@
* 6894719 6968053 7151434 7146424
* @summary Argument parsing validation.
* @compile -XDignore.symbol.file Arrrghs.java
- * @run main Arrrghs
+ * @run main/othervm Arrrghs
*/
import java.io.BufferedReader;
@@ -204,8 +204,7 @@
// exiting the process prematurely can terminate the stderr.
scratchpad.add(javaCmd + " -version " + inArgs);
File batFile = new File("atest.bat");
- java.nio.file.Files.deleteIfExists(batFile.toPath());
- createFile(batFile, scratchpad);
+ createAFile(batFile, scratchpad);
TestResult tr = doExec(batFile.getName());
--- a/jdk/test/tools/launcher/TestHelper.java Thu Dec 06 21:55:55 2012 -0800
+++ b/jdk/test/tools/launcher/TestHelper.java Sun Dec 09 07:43:12 2012 -0800
@@ -358,6 +358,51 @@
Files.copy(src.toPath(), dst.toPath(), COPY_ATTRIBUTES, REPLACE_EXISTING);
}
+ /**
+ * Attempt to create a file at the given location. If an IOException
+ * occurs then back off for a moment and try again. When a number of
+ * attempts fail, give up and throw an exception.
+ */
+ void createAFile(File aFile, List<String> contents) throws IOException {
+ IOException cause = null;
+ for (int attempts = 0; attempts < 10; attempts++) {
+ try {
+ Files.write(aFile.getAbsoluteFile().toPath(), contents,
+ Charset.defaultCharset(), CREATE, TRUNCATE_EXISTING, WRITE);
+ if (cause != null) {
+ /*
+ * report attempts and errors that were encountered
+ * for diagnostic purposes
+ */
+ System.err.println("Created batch file " +
+ aFile + " in " + (attempts + 1) +
+ " attempts");
+ System.err.println("Errors encountered: " + cause);
+ cause.printStackTrace();
+ }
+ return;
+ } catch (IOException ioe) {
+ if (cause != null) {
+ // chain the exceptions so they all get reported for diagnostics
+ cause.addSuppressed(ioe);
+ } else {
+ cause = ioe;
+ }
+ }
+
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException ie) {
+ if (cause != null) {
+ // cause should alway be non-null here
+ ie.addSuppressed(cause);
+ }
+ throw new RuntimeException("Interrupted while creating batch file", ie);
+ }
+ }
+ throw new RuntimeException("Unable to create batch file", cause);
+ }
+
static void createFile(File outFile, List<String> content) throws IOException {
Files.write(outFile.getAbsoluteFile().toPath(), content,
Charset.defaultCharset(), CREATE_NEW);