Skip to content

Commit cc8c852

Browse files
committed
Specific check for parent of MethodInvocationInfo ClassLoader
See gh-30389
1 parent fe7f8e2 commit cc8c852

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -780,11 +780,24 @@ private static <T> T initProxy(
780780

781781
else if (controllerType.isInterface()) {
782782
ClassLoader classLoader = controllerType.getClassLoader();
783-
if (classLoader == null || classLoader.getParent() == null) {
784-
// JDK interface type from bootstrap loader or platform loader ->
785-
// use higher-level loader which can see Spring infrastructure classes
783+
if (classLoader == null) {
784+
// JDK bootstrap loader -> use MethodInvocationInfo ClassLoader instead.
786785
classLoader = MethodInvocationInfo.class.getClassLoader();
787786
}
787+
else if (classLoader.getParent() == null) {
788+
// Potentially the JDK platform loader on JDK 9+
789+
ClassLoader miiClassLoader = MethodInvocationInfo.class.getClassLoader();
790+
ClassLoader miiParent = miiClassLoader.getParent();
791+
while (miiParent != null) {
792+
if (classLoader == miiParent) {
793+
// Suggested ClassLoader is ancestor of MethodInvocationInfo ClassLoader
794+
// -> use MethodInvocationInfo ClassLoader itself instead.
795+
classLoader = miiClassLoader;
796+
break;
797+
}
798+
miiParent = miiParent.getParent();
799+
}
800+
}
788801
Class<?>[] ifcs = new Class<?>[] {controllerType, MethodInvocationInfo.class};
789802
return (T) Proxy.newProxyInstance(classLoader, ifcs, interceptor);
790803
}

0 commit comments

Comments
 (0)