Skip to content

Commit

Permalink
AnnotationUtils.clearCache() includes all annotation caches
Browse files Browse the repository at this point in the history
Closes gh-31170

(cherry picked from commit 78fce80)
  • Loading branch information
jhoeller committed Sep 11, 2023
1 parent 0c3d8d7 commit 39c225c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
Expand Up @@ -1083,6 +1083,9 @@ protected void doClose() {
// Let subclasses do some final clean-up if they wish...
onClose();

// Reset common introspection caches to avoid class reference leaks.
resetCommonCaches();

// Reset local application listeners to pre-refresh state.
if (this.earlyApplicationListeners != null) {
this.applicationListeners.clear();
Expand Down
Expand Up @@ -1321,6 +1321,9 @@ public static boolean isSynthesizedAnnotation(@Nullable Annotation annotation) {
public static void clearCache() {
AnnotationTypeMappings.clearCache();
AnnotationsScanner.clearCache();
AttributeMethods.cache.clear();
RepeatableContainers.cache.clear();
OrderUtils.orderCache.clear();
}


Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,9 +39,7 @@ final class AttributeMethods {

static final AttributeMethods NONE = new AttributeMethods(null, new Method[0]);


private static final Map<Class<? extends Annotation>, AttributeMethods> cache =
new ConcurrentReferenceHashMap<>();
static final Map<Class<? extends Annotation>, AttributeMethods> cache = new ConcurrentReferenceHashMap<>();

private static final Comparator<Method> methodComparator = (m1, m2) -> {
if (m1 != null && m2 != null) {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,7 +41,7 @@ public abstract class OrderUtils {
private static final String JAVAX_PRIORITY_ANNOTATION = "javax.annotation.Priority";

/** Cache for @Order value (or NOT_ANNOTATED marker) per Class. */
private static final Map<AnnotatedElement, Object> orderCache = new ConcurrentReferenceHashMap<>(64);
static final Map<AnnotatedElement, Object> orderCache = new ConcurrentReferenceHashMap<>(64);


/**
Expand Down
Expand Up @@ -43,6 +43,8 @@
*/
public abstract class RepeatableContainers {

static final Map<Class<? extends Annotation>, Object> cache = new ConcurrentReferenceHashMap<>();

@Nullable
private final RepeatableContainers parent;

Expand Down Expand Up @@ -137,8 +139,6 @@ public static RepeatableContainers none() {
*/
private static class StandardRepeatableContainers extends RepeatableContainers {

private static final Map<Class<? extends Annotation>, Object> cache = new ConcurrentReferenceHashMap<>();

private static final Object NONE = new Object();

private static StandardRepeatableContainers INSTANCE = new StandardRepeatableContainers();
Expand Down

0 comments on commit 39c225c

Please sign in to comment.