From 89ceaa9e99bee17f270541ebdbdd03794c4e97ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Kubitz?= Date: Wed, 14 Aug 2024 12:53:59 +0200 Subject: [PATCH] Fix BatchCompilerTest - ZipFile "used by another process" on win #2766 https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2766 Works around error in JDK which forgets to close Jar when System.getSecurityManager()==null As workaround trigger a GC to make a associated Cleaner Run for the ZipFile no longer referenced. --- .../src/org/eclipse/jdt/core/tests/util/Util.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java index 92808138853..1ff6ef87c04 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java @@ -1306,12 +1306,17 @@ private static boolean waitUntilFileDeleted(File file) { System.out.print(" - wait for ("+DELETE_MAX_WAIT+"ms max): "); } int count = 0; - int delay = 10; // ms + int delay = 1; // ms int maxRetry = DELETE_MAX_WAIT / delay; int time = 0; while (count < maxRetry) { try { count++; + + // manually trigger GC to invoke Cleaner for ZipFile that is forgotten to be closed + // see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2766 + System.gc(); // workaround + Thread.sleep(delay); time += delay; if (time > DELETE_MAX_TIME) DELETE_MAX_TIME = time;