Skip to content

Commit

Permalink
6819122: DefaultProxySelector should lazily initialize the Pattern ob…
Browse files Browse the repository at this point in the history
…ject and the NonProxyInfo objects

Move two static NonProxyInfo fields into NonProxyInfo class and instantiate Pattern object when needed

Reviewed-by: jccollet
  • Loading branch information
Mandy Chung committed Mar 25, 2009
1 parent 01a3601 commit 5d6fffa
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions jdk/src/share/classes/sun/net/spi/DefaultProxySelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public class DefaultProxySelector extends ProxySelector {
};

private static boolean hasSystemProxies = false;
private static Properties defprops = new Properties();

static {
final String key = "java.net.useSystemProxies";
Expand Down Expand Up @@ -107,15 +106,16 @@ static class NonProxyInfo {
RegexpPool hostsPool;
String property;

static NonProxyInfo ftpNonProxyInfo = new NonProxyInfo("ftp.nonProxyHosts", null, null);
static NonProxyInfo httpNonProxyInfo = new NonProxyInfo("http.nonProxyHosts", null, null);

NonProxyInfo(String p, String s, RegexpPool pool) {
property = p;
hostsSource = s;
hostsPool = pool;
}
}

private static NonProxyInfo ftpNonProxyInfo = new NonProxyInfo("ftp.nonProxyHosts", null, null);
private static NonProxyInfo httpNonProxyInfo = new NonProxyInfo("http.nonProxyHosts", null, null);

/**
* select() method. Where all the hard work is done.
Expand Down Expand Up @@ -175,13 +175,13 @@ public java.util.List<Proxy> select(URI uri) {
NonProxyInfo pinfo = null;

if ("http".equalsIgnoreCase(protocol)) {
pinfo = httpNonProxyInfo;
pinfo = NonProxyInfo.httpNonProxyInfo;
} else if ("https".equalsIgnoreCase(protocol)) {
// HTTPS uses the same property as HTTP, for backward
// compatibility
pinfo = httpNonProxyInfo;
pinfo = NonProxyInfo.httpNonProxyInfo;
} else if ("ftp".equalsIgnoreCase(protocol)) {
pinfo = ftpNonProxyInfo;
pinfo = NonProxyInfo.ftpNonProxyInfo;
}

/**
Expand Down Expand Up @@ -334,7 +334,6 @@ private int defaultPort(String protocol) {
}
}

private static final Pattern p6 = Pattern.compile("::1|(0:){7}1|(0:){1,6}:1");
private boolean isLoopback(String host) {
if (host == null || host.length() == 0)
return false;
Expand Down Expand Up @@ -364,6 +363,7 @@ private boolean isLoopback(String host) {
}

if (host.endsWith(":1")) {
final Pattern p6 = Pattern.compile("::1|(0:){7}1|(0:){1,6}:1");
return p6.matcher(host).matches();
}
return false;
Expand Down

0 comments on commit 5d6fffa

Please sign in to comment.