From 2b4c1e265c7fd3d1baa52da137831136d486ce1e Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 14 Sep 2023 16:45:16 +0200 Subject: [PATCH] Reset findLoadedClassMethod in case of makeAccessible failing Closes gh-31232 --- .../context/support/ContextTypeMatchClassLoader.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-context/src/main/java/org/springframework/context/support/ContextTypeMatchClassLoader.java b/spring-context/src/main/java/org/springframework/context/support/ContextTypeMatchClassLoader.java index c4e228c3c1e5..998d061ca2cd 100644 --- a/spring-context/src/main/java/org/springframework/context/support/ContextTypeMatchClassLoader.java +++ b/spring-context/src/main/java/org/springframework/context/support/ContextTypeMatchClassLoader.java @@ -55,7 +55,7 @@ class ContextTypeMatchClassLoader extends DecoratingClassLoader implements Smart // override classes that have not been loaded yet. If not accessible, we will // always override requested classes, even when the classes have been loaded // by the parent ClassLoader already and cannot be transformed anymore anyway. - Method method = null; + Method method; try { method = ClassLoader.class.getDeclaredMethod("findLoadedClass", String.class); ReflectionUtils.makeAccessible(method); @@ -63,6 +63,7 @@ class ContextTypeMatchClassLoader extends DecoratingClassLoader implements Smart catch (Throwable ex) { // Typically a JDK 9+ InaccessibleObjectException... // Avoid through JVM startup with --add-opens=java.base/java.lang=ALL-UNNAMED + method = null; LogFactory.getLog(ContextTypeMatchClassLoader.class).debug( "ClassLoader.findLoadedClass not accessible -> will always override requested class", ex); }