Skip to content

Commit ed5696d

Browse files
Charlie Graciedfuch
authored andcommitted
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. Reviewed-by: dfuchs
1 parent 688e5d9 commit ed5696d

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
@@ -48,17 +48,21 @@
4848

4949
public class HttpURLConWithProxy {
5050

51+
private static Logger logger =
52+
Logger.getLogger("sun.net.www.protocol.http.HttpURLConnection");
53+
5154
public static void main(String... arg) throws Exception {
5255
// Remove the default nonProxyHosts to use localhost for testing
5356
System.setProperty("http.nonProxyHosts", "");
5457

5558
System.setProperty("http.proxyHost", "1.1.1.1");
5659
System.setProperty("http.proxyPort", "1111");
57-
String HTTPLOG = "sun.net.www.protocol.http.HttpURLConnection";
58-
Logger.getLogger(HTTPLOG).setLevel(Level.ALL);
60+
61+
// Use the logger to help verify the Proxy was used
62+
logger.setLevel(Level.ALL);
5963
Handler h = new ProxyHandler();
6064
h.setLevel(Level.ALL);
61-
Logger.getLogger(HTTPLOG).addHandler(h);
65+
logger.addHandler(h);
6266

6367
ServerSocket ss;
6468
URL url;

0 commit comments

Comments
 (0)