Skip to content

Commit 35b7418

Browse files
committed
Fix test ordering problems by always clearing URL stream handler factory
Closes gh-19349
1 parent 3cadde0 commit 35b7418

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.io.File;
2020
import java.io.IOException;
2121
import java.net.URISyntaxException;
22-
import java.net.URL;
2322
import java.nio.charset.Charset;
2423
import java.nio.charset.StandardCharsets;
2524
import java.time.Duration;
@@ -54,7 +53,6 @@
5453
import org.apache.catalina.startup.Tomcat;
5554
import org.apache.catalina.util.CharsetMapper;
5655
import org.apache.catalina.valves.RemoteIpValve;
57-
import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
5856
import org.apache.jasper.servlet.JspServlet;
5957
import org.apache.tomcat.JarScanFilter;
6058
import org.apache.tomcat.JarScanType;
@@ -75,7 +73,6 @@
7573
import org.springframework.http.HttpStatus;
7674
import org.springframework.http.MediaType;
7775
import org.springframework.http.ResponseEntity;
78-
import org.springframework.test.util.ReflectionTestUtils;
7976
import org.springframework.util.FileSystemUtils;
8077
import org.springframework.util.LinkedMultiValueMap;
8178
import org.springframework.util.MultiValueMap;
@@ -108,8 +105,6 @@ protected TomcatServletWebServerFactory getFactory() {
108105

109106
@After
110107
public void restoreTccl() {
111-
ReflectionTestUtils.setField(TomcatURLStreamHandlerFactory.class, "instance", null);
112-
ReflectionTestUtils.setField(URL.class, "factory", null);
113108
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
114109
}
115110

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import javax.servlet.http.HttpServletResponse;
6868
import javax.servlet.http.HttpSession;
6969

70+
import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
7071
import org.apache.http.client.HttpClient;
7172
import org.apache.http.client.entity.InputStreamFactory;
7273
import org.apache.http.client.protocol.HttpClientContext;
@@ -111,6 +112,7 @@
111112
import org.springframework.http.client.ClientHttpResponse;
112113
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
113114
import org.springframework.test.util.ReflectionTestUtils;
115+
import org.springframework.util.ClassUtils;
114116
import org.springframework.util.FileCopyUtils;
115117
import org.springframework.util.SocketUtils;
116118
import org.springframework.util.StreamUtils;
@@ -161,6 +163,15 @@ public void tearDown() {
161163
}
162164
}
163165

166+
@After
167+
public void clearUrlStreamHandlerFactory() {
168+
if (ClassUtils.isPresent("org.apache.catalina.webresources.TomcatURLStreamHandlerFactory",
169+
getClass().getClassLoader())) {
170+
ReflectionTestUtils.setField(TomcatURLStreamHandlerFactory.class, "instance", null);
171+
ReflectionTestUtils.setField(URL.class, "factory", null);
172+
}
173+
}
174+
164175
@Test
165176
public void startServlet() throws Exception {
166177
AbstractServletWebServerFactory factory = getFactory();

0 commit comments

Comments
 (0)