Skip to content

Commit b4c6c55

Browse files
committed
Allow ResourcesClassLoader to participate in CGLIB's cache
This commit updates ResourcesClassLoader to be a SmartClassLoader and expose the original ClassLoader. This has the effect of making sure proxies that are created by CGLIB can be reused against different tests rather than having CGLIB trying to define the class again and fail. Closes gh-45065
1 parent 19d74cf commit b4c6c55

File tree

1 file changed

+14
-1
lines changed
  • spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath/resources

1 file changed

+14
-1
lines changed

spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath/resources/ResourcesClassLoader.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@
1919
import java.io.IOException;
2020
import java.io.UncheckedIOException;
2121
import java.net.URL;
22+
import java.security.ProtectionDomain;
2223
import java.util.ArrayList;
2324
import java.util.Collections;
2425
import java.util.Enumeration;
2526

27+
import org.springframework.core.SmartClassLoader;
28+
2629
/**
2730
* A {@link ClassLoader} that provides access to {@link Resources resources}.
2831
*
2932
* @author Andy Wilkinson
3033
*/
31-
class ResourcesClassLoader extends ClassLoader {
34+
class ResourcesClassLoader extends ClassLoader implements SmartClassLoader {
3235

3336
private final Resources resources;
3437

@@ -66,4 +69,14 @@ public Enumeration<URL> getResources(String name) throws IOException {
6669
return Collections.enumeration(urls);
6770
}
6871

72+
@Override
73+
public ClassLoader getOriginalClassLoader() {
74+
return getParent();
75+
}
76+
77+
@Override
78+
public Class<?> publicDefineClass(String name, byte[] b, ProtectionDomain protectionDomain) {
79+
return defineClass(name, b, 0, b.length, protectionDomain);
80+
}
81+
6982
}

0 commit comments

Comments
 (0)