8196425: tools/javac/modules/AnnotationProcessing.java failed

Reviewed-by: jlahoda
This commit is contained in:
Jonathan Gibbons 2018-06-21 13:29:44 -07:00
parent 76d0843d18
commit f0b244a4ac

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -568,7 +568,7 @@ public class AnnotationProcessing extends ModuleTestBase {
"--module-source-path", moduleSrc.toString());
assertFileExists(classes, "m1x", "api1", "Impl.class");
Files.delete(m1.resolve("test").resolve("Test.java"));
deleteFile(m1.resolve("test").resolve("Test.java"));
//resource class output:
runCompiler(base,
@ -623,7 +623,7 @@ public class AnnotationProcessing extends ModuleTestBase {
assertFileExists(classes, "m1x", pack, "Pass.class");
assertFileNotExists(classes, "m2x", pack, "Pass.class");
Files.delete(m1.resolve("test").resolve("Test.java"));
deleteFile(m1.resolve("test").resolve("Test.java"));
runCompiler(base,
moduleSrc,
@ -694,6 +694,36 @@ public class AnnotationProcessing extends ModuleTestBase {
}
}
private void deleteFile(Path file) throws IOException {
long startTime = System.currentTimeMillis();
do {
Files.delete(file);
if (!Files.exists(file)) {
return;
}
System.err.println("!! File not deleted !!");
System.gc(); // allow finalizers and cleaners to run
try {
Thread.sleep(RETRY_DELETE_MILLIS);
} catch (InterruptedException e) {
throw new IOException("Interrupted while deleting " + file, e);
}
} while ((System.currentTimeMillis() - startTime) <= MAX_RETRY_DELETE_MILLIS);
throw new IOException("Can't delete " + file);
}
private static final int RETRY_DELETE_MILLIS;
private static final int MAX_RETRY_DELETE_MILLIS;
static {
boolean isWindows = System.getProperty("os.name").startsWith("Windows");
RETRY_DELETE_MILLIS = isWindows ? 500 : 0;
MAX_RETRY_DELETE_MILLIS = isWindows ? 15 * 1000 : 0;
}
public static abstract class GeneratingAP extends AbstractProcessor {
public void createSource(CreateFileObject file, String name, String content) {
@ -842,7 +872,7 @@ public class AnnotationProcessing extends ModuleTestBase {
options);
assertFileExists(classes, modulePath, "impl", "Impl.class");
Files.delete(m1.resolve("test").resolve("Test.java"));
deleteFile(m1.resolve("test").resolve("Test.java"));
//resource class output:
runCompiler(base,
@ -869,7 +899,7 @@ public class AnnotationProcessing extends ModuleTestBase {
"expectFilerException(() -> filer.getResource(StandardLocation.SOURCE_PATH, \"m1x/impl\", \"resource\"))",
"-sourcepath", m1.toString());
Files.delete(m1.resolve("impl").resolve("resource"));
deleteFile(m1.resolve("impl").resolve("resource"));
//can read resources from the system module path if module name given:
runCompiler(base,
@ -930,7 +960,7 @@ public class AnnotationProcessing extends ModuleTestBase {
"-sourcepath", m1.toString());
}
Files.delete(m1.resolve("module-info.java"));
deleteFile(m1.resolve("module-info.java"));
tb.writeJavaFiles(m1,
"package test; class Test { }");