From 1a0e008a8ce51ded86ee71b7218c22227615ebc6 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 7 Jun 2021 19:16:56 +0100 Subject: [PATCH] Prevent Netty tcNative from loading classes with wrong class loader In our tests, the JNI code in Netty tcNative can cause some of its classes to be loaded using a ModifiedClassPathClassLoader. When the wrong class loader is used, SSL-related tests fail, for example due to the same Netty tcNative classes being loaded by two different ClassLoders and no longer being the same. This appears to be dependent upon the order in which tests are executed and results in intermittent test failures. It looks like this should be addressed in Netty tcNative 2.0.40 which preloads all of its classes. In the meantime, this commit updates ModifiedClassPathClassLodaer to ignore Netty tcNative classes so that they're only ever loaded by the system class loader. Closes gh-26749 --- .../testsupport/classpath/ModifiedClassPathClassLoader.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathClassLoader.java b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathClassLoader.java index 44259b95b3..adae5409fb 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathClassLoader.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathClassLoader.java @@ -77,7 +77,8 @@ final class ModifiedClassPathClassLoader extends URLClassLoader { @Override public Class loadClass(String name) throws ClassNotFoundException { - if (name.startsWith("org.junit") || name.startsWith("org.hamcrest")) { + if (name.startsWith("org.junit") || name.startsWith("org.hamcrest") + || name.startsWith("io.netty.internal.tcnative")) { return Class.forName(name, false, this.junitLoader); } return super.loadClass(name);