--- old/src/java.base/macosx/native/libnet/DefaultProxySelector.c 2017-01-31 11:35:51.000000000 +0000
+++ new/src/java.base/macosx/native/libnet/DefaultProxySelector.c 2017-01-31 11:35:50.000000000 +0000
@@ -61,8 +61,10 @@
}
/*
- * This will resolve all PAC URLs in the given array and return an array containing no more
- * PAC URLs.
+ * Returns a new array of proxies containing all the given non-PAC proxies as
+ * well as the results of executing all the given PAC-based proxies, for the
+ * specified URL. 'proxies' is a list that may contain both PAC and non-PAC
+ * proxies.
*/
static CFArrayRef createExpandedProxiesArray(CFArrayRef proxies, CFURLRef url) {
@@ -71,7 +73,8 @@
CFMutableArrayRef expandedProxiesArray;
expandedProxiesArray = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
- assert(expandedProxiesArray != NULL);
+ if (expandedProxiesArray == NULL)
+ return NULL;
/* Iterate over the array of proxies */
count = CFArrayGetCount(proxies);
@@ -80,15 +83,21 @@
CFStringRef proxyType;
currentProxy = (CFDictionaryRef) CFArrayGetValueAtIndex(proxies, index);
- assert(currentProxy != NULL);
+ if(currentProxy == NULL) {
+ CFRelease(expandedProxiesArray);
+ return NULL;
+ }
proxyType = (CFStringRef) CFDictionaryGetValue(currentProxy, kCFProxyTypeKey);
- assert(proxyType != NULL);
+ if (proxyType == NULL) {
+ CFRelease(expandedProxiesArray);
+ return NULL;
+ }
if (!CFEqual(proxyType, kCFProxyTypeAutoConfigurationURL)) {
- /* This is a non PAC entry - just copy it to the new array. */
+ /* Non-PAC entry, just copy it to the new array */
CFArrayAppendValue(expandedProxiesArray, currentProxy);
} else {
- /* This is a PAC URL and we have to resolve it. */
+ /* PAC-based URL, execute its script append its results */
CFRunLoopSourceRef runLoop;
CFURLRef scriptURL;
CFTypeRef result = NULL;
@@ -109,14 +118,14 @@
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), runLoop, kResolveProxyRunLoopMode);
/*
- * Once the runloop returns, we should have either an error result or a
- * proxies array result. Do the appropriate thing with that result.
+ * Once the runloop returns, there will be either an error result or
+ * a proxies array result. Do the appropriate thing with that result.
*/
if (result != NULL) {
if (CFGetTypeID(result) == CFArrayGetTypeID()) {
/*
- * Append the new array from the PAC list - it does
- * contain no more PAC URIs.
+ * Append the new array from the PAC list - it contains
+ * only non-PAC entries.
*/
CFArrayAppendArray(expandedProxiesArray, result,
CFRangeMake(0, CFArrayGetCount(result)));
@@ -205,6 +214,12 @@
CFArrayRef expandedProxyArray = createExpandedProxiesArray(urlProxyArrayRef, urlRef);
CFRelease(urlProxyArrayRef);
+ if (expandedProxyArray == NULL) {
+ CFRelease(urlRef);
+ CFRelease(proxyDicRef);
+ return NULL;
+ }
+
count = CFArrayGetCount(expandedProxyArray);
proxyArray = (*env)->NewObjectArray(env, count, proxy_class, NULL);
@@ -219,15 +234,12 @@
index);
proxyType = (CFStringRef) CFDictionaryGetValue(currentProxy, kCFProxyTypeKey);
if (CFEqual(proxyType, kCFProxyTypeNone)) {
- /*
- * This entry states we should use no proxy - therefor we just create a
- * NO_PROXY object.
- */
+ /* This entry states no proxy, therefore just add a NO_PROXY object. */
proxy = (*env)->GetStaticObjectField(env, proxy_class, pr_no_proxyID);
} else {
/*
- * Create a proxy object for this entry. We have to differentiate between
- * socks and http type.
+ * Create a proxy object for this entry.
+ * Differentiate between SOCKS and HTTP type.
*/
jfieldID typeID = ptype_httpID;
if (CFEqual(proxyType, kCFProxyTypeSOCKS)) {
--- old/src/java.base/share/classes/sun/net/spi/DefaultProxySelector.java 2017-01-31 11:35:54.000000000 +0000
+++ new/src/java.base/share/classes/sun/net/spi/DefaultProxySelector.java 2017-01-31 11:35:53.000000000 +0000
@@ -30,16 +30,19 @@
import java.net.ProxySelector;
import java.net.SocketAddress;
import java.net.URI;
-import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.StringJoiner;
import java.util.regex.Pattern;
+import java.util.stream.Stream;
import sun.net.NetProperties;
import sun.net.SocksProxy;
import static java.util.regex.Pattern.quote;
+import static java.util.stream.Collectors.collectingAndThen;
+import static java.util.stream.Collectors.toList;
/**
* Supports proxy settings using system properties This proxy selector
@@ -318,9 +321,16 @@
return null;
}});
- // If no specific proxy was found we return our standard list containing
+
+ if (proxyArray != null) {
+ // Remove duplicate entries, while preserving order.
+ return Stream.of(proxyArray).distinct().collect(
+ collectingAndThen(toList(), Collections::unmodifiableList));
+ }
+
+ // If no specific proxy was found, return a standard list containing
// only one NO_PROXY entry.
- return proxyArray == null ? NO_PROXY_LIST : List.of(proxyArray);
+ return NO_PROXY_LIST;
}
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
--- old/src/java.base/windows/native/libnet/DefaultProxySelector.c 2017-01-31 11:36:01.000000000 +0000
+++ new/src/java.base/windows/native/libnet/DefaultProxySelector.c 2017-01-31 11:36:00.000000000 +0000
@@ -34,10 +34,10 @@
#include "sun_net_spi_DefaultProxySelector.h"
-/**
+/*
* These functions are used by the sun.net.spi.DefaultProxySelector class
* to access some platform specific settings.
- * This is the Windows code using WinHTTP functions to get the system settings.
+ * On Windows use WinHTTP functions to get the system settings.
*/
/* Keep one static session for all requests. */
@@ -52,8 +52,8 @@
Java_sun_net_spi_DefaultProxySelector_init(JNIEnv *env, jclass clazz) {
/*
- * Get one WinHTTP session handle to initialize the WinHTTP internal data structures
- * We keep and use only this one for the whole life time.
+ * Get one WinHTTP session handle to initialize the WinHTTP internal data
+ * structures. Keep and use only this one for the whole life time.
*/
session = WinHttpOpen(L"Only used internal", /* we need no real agent string here */
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
@@ -107,8 +107,9 @@
BOOL error = FALSE;
/*
- * The proxy server list contains one or more of the following strings separated by semicolons or whitespace.
- * ([
java.net.useSystemProxies (default: false)
- On Windows systems, macOS systems and on Gnome 2.x systems it is possible to
+ On Windows systems, macOS systems and on Gnome systems it is possible to
tell the java.net stack, setting this property to true, to use
the system proxy settings (both these systems let you set proxies
globally through their user interface). Note that this property is