Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8251361: Potential race between Logger configuration and GCs in HttpU…
…RLConWithProxy test

Keep a static reference to the logger to prevent its inadvertent garbage collection while the test is running.

Reviewed-by: dfuchs
  • Loading branch information
Charlie Gracie authored and dfuch committed Aug 10, 2020
1 parent b09b36a commit 88297c1316434625ffe0651a4992129f90123744
Showing 1 changed file with 7 additions and 3 deletions.
@@ -48,17 +48,21 @@

public class HttpURLConWithProxy {

private static Logger logger =
Logger.getLogger("sun.net.www.protocol.http.HttpURLConnection");

public static void main(String... arg) throws Exception {
// Remove the default nonProxyHosts to use localhost for testing
System.setProperty("http.nonProxyHosts", "");

System.setProperty("http.proxyHost", "1.1.1.1");
System.setProperty("http.proxyPort", "1111");
String HTTPLOG = "sun.net.www.protocol.http.HttpURLConnection";
Logger.getLogger(HTTPLOG).setLevel(Level.ALL);

// Use the logger to help verify the Proxy was used
logger.setLevel(Level.ALL);
Handler h = new ProxyHandler();
h.setLevel(Level.ALL);
Logger.getLogger(HTTPLOG).addHandler(h);
logger.addHandler(h);

ServerSocket ss;
URL url;

0 comments on commit 88297c1

Please sign in to comment.