Skip to content

Commit c27acad

Browse files
committed
Specific check for parent of MethodInvocationInfo ClassLoader
See gh-30389
1 parent 70be9af commit c27acad

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
@@ -777,11 +777,24 @@ private static <T> T initProxy(
777777

778778
else if (controllerType.isInterface()) {
779779
ClassLoader classLoader = controllerType.getClassLoader();
780-
if (classLoader == null || classLoader.getParent() == null) {
781-
// JDK interface type from bootstrap loader or platform loader ->
782-
// use higher-level loader which can see Spring infrastructure classes
780+
if (classLoader == null) {
781+
// JDK bootstrap loader -> use MethodInvocationInfo ClassLoader instead.
783782
classLoader = MethodInvocationInfo.class.getClassLoader();
784783
}
784+
else if (classLoader.getParent() == null) {
785+
// Potentially the JDK platform loader on JDK 9+
786+
ClassLoader miiClassLoader = MethodInvocationInfo.class.getClassLoader();
787+
ClassLoader miiParent = miiClassLoader.getParent();
788+
while (miiParent != null) {
789+
if (classLoader == miiParent) {
790+
// Suggested ClassLoader is ancestor of MethodInvocationInfo ClassLoader
791+
// -> use MethodInvocationInfo ClassLoader itself instead.
792+
classLoader = miiClassLoader;
793+
break;
794+
}
795+
miiParent = miiParent.getParent();
796+
}
797+
}
785798
Class<?>[] ifcs = new Class<?>[] {controllerType, MethodInvocationInfo.class};
786799
return (T) Proxy.newProxyInstance(classLoader, ifcs, interceptor);
787800
}

0 commit comments

Comments
 (0)