Skip to content

Commit fc085e8

Browse files
committed
Reinstate Introspector.flushFromCaches() call for JDK ClassInfo cache
Closes gh-27781
1 parent 9d71549 commit fc085e8

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

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

Lines changed: 15 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.
@@ -248,9 +248,22 @@ private static BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionExce
248248
return beanInfo;
249249
}
250250
}
251-
return (shouldIntrospectorIgnoreBeaninfoClasses ?
251+
252+
BeanInfo beanInfo = (shouldIntrospectorIgnoreBeaninfoClasses ?
252253
Introspector.getBeanInfo(beanClass, Introspector.IGNORE_ALL_BEANINFO) :
253254
Introspector.getBeanInfo(beanClass));
255+
256+
// Immediately remove class from Introspector cache to allow for proper garbage
257+
// collection on class loader shutdown; we cache it in CachedIntrospectionResults
258+
// in a GC-friendly manner. This is necessary (again) for the JDK ClassInfo cache.
259+
Class<?> classToFlush = beanClass;
260+
do {
261+
Introspector.flushFromCaches(classToFlush);
262+
classToFlush = classToFlush.getSuperclass();
263+
}
264+
while (classToFlush != null && classToFlush != Object.class);
265+
266+
return beanInfo;
254267
}
255268

256269

0 commit comments

Comments
 (0)