From fc085e8663a0fa654830b8333f8881f429678cda Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 7 Aug 2023 15:07:33 +0200 Subject: [PATCH] Reinstate Introspector.flushFromCaches() call for JDK ClassInfo cache Closes gh-27781 --- .../beans/CachedIntrospectionResults.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java b/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java index 42e9acca27f..1af0bde135c 100644 --- a/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java +++ b/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java @@ -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. @@ -248,9 +248,22 @@ public final class CachedIntrospectionResults { return beanInfo; } } - return (shouldIntrospectorIgnoreBeaninfoClasses ? + + BeanInfo beanInfo = (shouldIntrospectorIgnoreBeaninfoClasses ? Introspector.getBeanInfo(beanClass, Introspector.IGNORE_ALL_BEANINFO) : Introspector.getBeanInfo(beanClass)); + + // Immediately remove class from Introspector cache to allow for proper garbage + // collection on class loader shutdown; we cache it in CachedIntrospectionResults + // in a GC-friendly manner. This is necessary (again) for the JDK ClassInfo cache. + Class classToFlush = beanClass; + do { + Introspector.flushFromCaches(classToFlush); + classToFlush = classToFlush.getSuperclass(); + } + while (classToFlush != null && classToFlush != Object.class); + + return beanInfo; }