Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear the Introspector caches in tests #41604

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.test;

import java.beans.Introspector;
import java.lang.reflect.Field;
import java.util.Map;

Expand All @@ -10,14 +11,28 @@ public class ClearCache {

private static final Logger log = Logger.getLogger(ClearCache.class);

public static void clearAnnotationCache() {
public static void clearCaches() {
clearAnnotationCache();
clearBeansIntrospectorCache();
}

private static void clearAnnotationCache() {
try {
Field f = AnnotationUtils.class.getDeclaredField("repeatableAnnotationContainerCache");
f.setAccessible(true);
((Map) (f.get(null))).clear();
} catch (NoSuchFieldException | IllegalAccessException e) {
//ignore
log.debug("Failed to clear cache", e);
log.debug("Failed to clear annotation cache", e);
}
}

private static void clearBeansIntrospectorCache() {
try {
Introspector.flushCaches();
} catch (Exception e) {
//ignore
log.debug("Failed to clear java.beans.Introspector cache", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public void afterAll(ExtensionContext context) throws Exception {
rootLogger.setHandlers(originalRootLoggerHandlers);
inMemoryLogHandler.clearRecords();
inMemoryLogHandler.setFilter(null);
ClearCache.clearAnnotationCache();
ClearCache.clearCaches();
TestConfigUtil.cleanUp();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ public void afterAll(ExtensionContext extensionContext) throws Exception {
if (afterAllCustomizer != null) {
afterAllCustomizer.run();
}
ClearCache.clearAnnotationCache();
ClearCache.clearCaches();
TestConfigUtil.cleanUp();
}
if (records != null) {
Expand Down
Loading