Apache Lucene open-source search software
LUCENE-5577: the cleanup code didn't cleanup after itself...
Dawid Weissa0e6d12d003d
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.javaindex 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<Throwable> 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<Throwable> 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;}- throw e;}- }- } else {- synchronized (cleanupQueue) {- if (tempDirBase != null) {- System.err.println("NOTE: leaving temporary files on disk at: " +- tempDirBase.getAbsolutePath());+ } else {+ synchronized (cleanupQueue) {+ if (tempDirBase != null) {+ System.err.println("NOTE: leaving temporary files on disk at: " ++ tempDirBase.getAbsolutePath());+ }}}+ } finally {+ tempDirBase = null;}}}