Skip to content

Commit

Permalink
8251361: Potential race between Logger configuration and GCs in HttpU…
Browse files Browse the repository at this point in the history
…RLConWithProxy test

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

Backport-of: ed5696d
  • Loading branch information
shipilev committed Aug 13, 2021
1 parent 94b633a commit d8e1e62
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions test/jdk/java/net/HttpURLConnection/HttpURLConWithProxy.java
Expand Up @@ -45,17 +45,21 @@

public class HttpURLConWithProxy {

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

public static void main(String... arg) {
// 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;
Expand Down

1 comment on commit d8e1e62

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.