Skip to content

Commit 156b369

Browse files
committed
Reinstate Introspector.flushFromCaches() call for JDK ClassInfo cache
Closes gh-27781
1 parent c36174b commit 156b369

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

spring-beans/src/main/java/org/springframework/beans/StandardBeanInfoFactory.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -68,9 +68,21 @@ public class StandardBeanInfoFactory implements BeanInfoFactory, Ordered {
6868
@Override
6969
@NonNull
7070
public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
71-
return (shouldIntrospectorIgnoreBeaninfoClasses ?
71+
BeanInfo beanInfo = (shouldIntrospectorIgnoreBeaninfoClasses ?
7272
Introspector.getBeanInfo(beanClass, Introspector.IGNORE_ALL_BEANINFO) :
7373
Introspector.getBeanInfo(beanClass));
74+
75+
// Immediately remove class from Introspector cache to allow for proper garbage
76+
// collection on class loader shutdown; we cache it in CachedIntrospectionResults
77+
// in a GC-friendly manner. This is necessary (again) for the JDK ClassInfo cache.
78+
Class<?> classToFlush = beanClass;
79+
do {
80+
Introspector.flushFromCaches(classToFlush);
81+
classToFlush = classToFlush.getSuperclass();
82+
}
83+
while (classToFlush != null && classToFlush != Object.class);
84+
85+
return beanInfo;
7486
}
7587

7688
@Override

0 commit comments

Comments
 (0)