Skip to content

Commit d8e1e62

Browse files
committed
8251361: Potential race between Logger configuration and GCs in HttpURLConWithProxy test
Keep a static reference to the logger to prevent its inadvertent garbage collection while the test is running. Backport-of: ed5696d
1 parent 94b633a commit d8e1e62

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

test/jdk/java/net/HttpURLConnection/HttpURLConWithProxy.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,21 @@
4545

4646
public class HttpURLConWithProxy {
4747

48+
private static Logger logger =
49+
Logger.getLogger("sun.net.www.protocol.http.HttpURLConnection");
50+
4851
public static void main(String... arg) {
4952
// Remove the default nonProxyHosts to use localhost for testing
5053
System.setProperty("http.nonProxyHosts", "");
5154

5255
System.setProperty("http.proxyHost", "1.1.1.1");
5356
System.setProperty("http.proxyPort", "1111");
54-
String HTTPLOG = "sun.net.www.protocol.http.HttpURLConnection";
55-
Logger.getLogger(HTTPLOG).setLevel(Level.ALL);
57+
58+
// Use the logger to help verify the Proxy was used
59+
logger.setLevel(Level.ALL);
5660
Handler h = new ProxyHandler();
5761
h.setLevel(Level.ALL);
58-
Logger.getLogger(HTTPLOG).addHandler(h);
62+
logger.addHandler(h);
5963

6064
ServerSocket ss;
6165
URL url;

0 commit comments

Comments
 (0)