Skip to content

Commit f2287e7

Browse files
authored
Refactor the use of runFinalization in tests and benchmarks (#12768)
This commit refactors the usage of the deprecated System::runFinalization in tests and benchmarks, so that narrowly targeted suppressions can be added.
1 parent 1930425 commit f2287e7

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/PerfRunData.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.apache.lucene.store.Directory;
4747
import org.apache.lucene.store.FSDirectory;
4848
import org.apache.lucene.util.IOUtils;
49+
import org.apache.lucene.util.SuppressForbidden;
4950

5051
/**
5152
* Data maintained by a performance test run.
@@ -204,7 +205,7 @@ public void reinit(boolean eraseIndex) throws Exception {
204205
resetInputs();
205206

206207
// release unused stuff
207-
System.runFinalization();
208+
runFinalization();
208209
System.gc();
209210

210211
// Re-init clock
@@ -482,4 +483,10 @@ public synchronized QueryMaker getQueryMaker(ReadTask readTask) {
482483
public Map<String, AnalyzerFactory> getAnalyzerFactories() {
483484
return analyzerFactories;
484485
}
486+
487+
@SuppressWarnings("removal")
488+
@SuppressForbidden(reason = "requires to run finalization")
489+
private static void runFinalization() {
490+
System.runFinalization();
491+
}
485492
}

lucene/core/src/test/org/apache/lucene/util/TestWeakIdentityMap.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void testSimpleHashMap() {
119119
int size = map.size();
120120
for (int i = 0; size > 0 && i < 10; i++)
121121
try {
122-
System.runFinalization();
122+
runFinalization();
123123
System.gc();
124124
int newSize = map.size();
125125
assertTrue("previousSize(" + size + ")>=newSize(" + newSize + ")", size >= newSize);
@@ -232,7 +232,7 @@ public void run() {
232232
int size = map.size();
233233
for (int i = 0; size > 0 && i < 10; i++)
234234
try {
235-
System.runFinalization();
235+
runFinalization();
236236
System.gc();
237237
int newSize = map.size();
238238
assertTrue("previousSize(" + size + ")>=newSize(" + newSize + ")", size >= newSize);
@@ -252,4 +252,10 @@ public void run() {
252252
InterruptedException ie) {
253253
}
254254
}
255+
256+
@SuppressWarnings("removal")
257+
@SuppressForbidden(reason = "requires to run finalization")
258+
private static void runFinalization() {
259+
System.runFinalization();
260+
}
255261
}

0 commit comments

Comments
 (0)