Improve error message when DirtiesUrlFactoriesExtension fails
See gh-33019
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.testsupport.web.servlet;
|
||||
|
||||
import java.lang.reflect.InaccessibleObjectException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.junit.jupiter.api.extension.AfterEachCallback;
|
||||
@@ -45,12 +46,18 @@ class DirtiesUrlFactoriesExtension implements BeforeEachCallback, AfterEachCallb
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
if (ClassUtils.isPresent(TOMCAT_URL_STREAM_HANDLER_FACTORY, classLoader)) {
|
||||
Class<?> factoryClass = ClassUtils.resolveClassName(TOMCAT_URL_STREAM_HANDLER_FACTORY, classLoader);
|
||||
ReflectionTestUtils.setField(factoryClass, "instance", null);
|
||||
try {
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
if (ClassUtils.isPresent(TOMCAT_URL_STREAM_HANDLER_FACTORY, classLoader)) {
|
||||
Class<?> factoryClass = ClassUtils.resolveClassName(TOMCAT_URL_STREAM_HANDLER_FACTORY, classLoader);
|
||||
ReflectionTestUtils.setField(factoryClass, "instance", null);
|
||||
}
|
||||
ReflectionTestUtils.setField(URL.class, "factory", null);
|
||||
}
|
||||
catch (InaccessibleObjectException ex) {
|
||||
throw new IllegalStateException(
|
||||
"Unable to reset field. Please run with '--add-opens=java.base/java.net=ALL-UNNAMED'", ex);
|
||||
}
|
||||
ReflectionTestUtils.setField(URL.class, "factory", null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user