Skip to content

Commit

Permalink
Merge pull request #41604 from gsmet/introspector-cache
Browse files Browse the repository at this point in the history
Clear the Introspector caches in tests
  • Loading branch information
geoand authored Jul 2, 2024
2 parents ca73df4 + bff1924 commit 0fb113e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
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

0 comments on commit 0fb113e

Please sign in to comment.