8318150: StaticProxySelector.select should not throw NullPointerExceptions

Reviewed-by: jpai, dfuchs
This commit is contained in:
Daniel Jeliński 2023-10-20 06:18:18 +00:00
parent c46a54e018
commit d9ce525a1c
2 changed files with 50 additions and 57 deletions

View file

@ -27,7 +27,6 @@ package java.net;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import sun.security.util.SecurityConstants;
@ -178,7 +177,8 @@ public abstract class ProxySelector {
/**
* Returns a ProxySelector which uses the given proxy address for all HTTP
* and HTTPS requests. If proxy is {@code null} then proxying is disabled.
* and HTTPS requests. If {@code proxyAddress} is {@code null}
* then proxying is disabled.
*
* @param proxyAddress
* The address of the proxy
@ -207,13 +207,22 @@ public abstract class ProxySelector {
@Override
public void connectFailed(URI uri, SocketAddress sa, IOException e) {
if (uri == null || sa == null || e == null) {
throw new IllegalArgumentException("Arguments can't be null.");
}
/* ignore */
}
@Override
public synchronized List<Proxy> select(URI uri) {
String scheme = uri.getScheme().toLowerCase(Locale.ROOT);
if (scheme.equals("http") || scheme.equals("https")) {
public List<Proxy> select(URI uri) {
if (uri == null) {
throw new IllegalArgumentException("URI can't be null");
}
String scheme = uri.getScheme();
if (scheme == null) {
throw new IllegalArgumentException("protocol can't be null");
}
if (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https")) {
return list;
} else {
return NO_PROXY_LIST;