diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java index 91bf8f3e10b..57933935d96 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java +++ b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java @@ -2338,35 +2338,45 @@ public abstract class LuceneTestCase extends Assert { private static class TemporaryFilesCleanupRule extends TestRuleAdapter { @Override - protected void afterAlways(List errors) throws Throwable { - if (LuceneTestCase.suiteFailureMarker.wasSuccessful()) { - synchronized (cleanupQueue) { - File [] everything = new File [cleanupQueue.size()]; - for (int i = 0; !cleanupQueue.isEmpty(); i++) { - everything[i] = cleanupQueue.removeLast(); - } + protected void before() throws Throwable { + super.before(); + assert tempDirBase == null; + } - // Will throw an IOException on un-removable files. - try { - TestUtil.rm(everything); - } catch (IOException e) { - Class suiteClass = RandomizedContext.current().getTargetClass(); - if (suiteClass.isAnnotationPresent(SuppressTempFileChecks.class)) { - System.err.println("WARNING: Leftover undeleted temporary files (bugUrl: " - + suiteClass.getAnnotation(SuppressTempFileChecks.class).bugUrl() + "): " - + e.getMessage()); - return; + @Override + protected void afterAlways(List errors) throws Throwable { + try { + if (LuceneTestCase.suiteFailureMarker.wasSuccessful()) { + synchronized (cleanupQueue) { + File [] everything = new File [cleanupQueue.size()]; + for (int i = 0; !cleanupQueue.isEmpty(); i++) { + everything[i] = cleanupQueue.removeLast(); + } + + // Will throw an IOException on un-removable files. + try { + TestUtil.rm(everything); + } catch (IOException e) { + Class suiteClass = RandomizedContext.current().getTargetClass(); + if (suiteClass.isAnnotationPresent(SuppressTempFileChecks.class)) { + System.err.println("WARNING: Leftover undeleted temporary files (bugUrl: " + + suiteClass.getAnnotation(SuppressTempFileChecks.class).bugUrl() + "): " + + e.getMessage()); + return; + } + throw e; + } + } + } else { + synchronized (cleanupQueue) { + if (tempDirBase != null) { + System.err.println("NOTE: leaving temporary files on disk at: " + + tempDirBase.getAbsolutePath()); } - throw e; - } - } - } else { - synchronized (cleanupQueue) { - if (tempDirBase != null) { - System.err.println("NOTE: leaving temporary files on disk at: " + - tempDirBase.getAbsolutePath()); } } + } finally { + tempDirBase = null; } } }