JDK-7014531 : [windows] DefaultProxySelector doesn't handle wildcard characters in bypass list
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 6u23
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_7
  • CPU: x86
  • Submitted: 2011-01-25
  • Updated: 2022-07-13
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
C:\Temp>java -version
java version "1.6.0_23"
Java(TM) SE Runtime Environment (build 1.6.0_23-b05)
Java HotSpot(TM) Client VM (build 19.0-b09, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7600]

EXTRA RELEVANT SYSTEM CONFIGURATION :
Sample proxy configuration for a LAN connection by completing these steps:

   1. Click Start, and then click Control Panel.
   2. Click Network and Internet, and then click Internet Options.
   3. In the Internet Options dialog box, click the Connections tab.
   4. Click the LAN Settings button.
   5. To enable the use of a proxy server, check the box for “Use a proxy server for your LAN.
   6. Enter the IP address of the proxy in the Address text box, i.e. wwwcache
   7. Enter the port number of the proxy in the Port text box, i.e. 1234
   8. To bypass the proxy server for local IP addresses, select the “Bypass proxy server for local addresses” checkbox.
   9. Click Advanced
   10. Enter the follwing addesses to the exception list:
       *.oracle.com;212.201.100.*
  11. Click OK to close the avanced settings.
  12. Click OK to complete the proxy configuration process.

A DESCRIPTION OF THE PROBLEM :
Although the system proxy hostname and port are taken into account, the bypass exceptions are not. Obviously the '*' wildcards are not considered correctly. by the way, if a proxy pac specifiaction is given it is not taken into account at all:-(

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Enter the "Additional Configuration Information" as described above.
Compile the proived Source Code and run it as follows:

java -Djava.net.useSystemProxies=true testProxy


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
java.net.useSystemProxies: null
http.proxyHost: wwwcache
http.proxyPort: 1234
http.nonproxyhosts: *.oracle.com|212.201.100.184
uri: http://www.oracle.com
  proxy hostname : DIRECT
  No Proxy
uri: http://212.201.100.184
  proxy hostname : DIRECT
  No Proxy
uri: http://www.yahoo.com
  proxy hostname : HTTP
  proxy hostname : wwwcache
  proxy port : 1234
uri: http://localhost
  proxy hostname : DIRECT
  No Proxy
ACTUAL -
java.net.useSystemProxies: true
http.proxyHost: null
http.proxyPort: null
http.nonproxyhosts: null
uri: http://www.oracle.com
  proxy hostname : HTTP
  proxy hostname : wwwcache
  proxy port : 1234
uri: http://212.201.100.184
  proxy hostname : HTTP
  proxy hostname : wwwcache
  proxy port : 1234
uri: http://www.yahoo.com
  proxy hostname : HTTP
  proxy hostname : wwwcache
  proxy port : 1234
uri: http://localhost
  proxy hostname : DIRECT
  No Proxy

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.URI;
import java.util.Iterator;
import java.util.List;


public class testProxy
{
  /** derived from http://www.rgagnon.com/javadetails/java-0085.html */
  public static void main(String[] args)
  {
    System.out.println("java.net.useSystemProxies: " + System.getProperty("java.net.useSystemProxies"));

    System.out.println("http.proxyHost: " + System.getProperty("http.proxyHost"));
    System.out.println("http.proxyPort: " + System.getProperty("http.proxyPort"));
    System.out.println("http.nonproxyhosts: " + System.getProperty("http.nonProxyHosts"));

    String[] uris = args != null && args.length > 0 ? args : new String[] {"http://www.oracle.com", "http://212.201.100.184", "http://www.yahoo.com", "http://localhost",};
    for (final String uri : uris)
    {
      System.out.println("uri: " + uri);
      try
      {
        ProxySelector dps = ProxySelector.getDefault();
        URI URI = new URI(uri);

        List<Proxy> pl = dps.select(URI);

        for (Iterator<Proxy> pli = pl.iterator(); pli.hasNext();)
        {
          Proxy proxy = pli.next();

          System.out.println("  proxy hostname : " + proxy.type());

          InetSocketAddress addr = (InetSocketAddress)proxy.address();
          if (addr == null)
          {
            System.out.println("  No Proxy");
          }
          else
          {
            System.out.println("  proxy hostname : " + addr.getHostName());
            System.out.println("  proxy port : " + addr.getPort());
          }
        }
      }
      catch (Exception e)
      {
        e.printStackTrace();
      }
    }
  }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Either enumerate the list of bypass addresses explicitly, e.g. "www.oracle.com;www1.oracle.com;212.201.100.184;..."

or fall back to the http.* properties where at least wildcards for FDNs are supported, e.g.

java -Dhttp.proxyHost=wwwcache -Dhttp.proxyPort=123 -Dhttp.nonProxyHosts="*.oracle.com|212.201.100.184" testProxy

However wildcards for IPs don't work either, e.g.

java -Dhttp.proxyHost=wwwcache -Dhttp.proxyPort=123 -Dhttp.nonProxyHosts="*.oracle.com|212.201.100.*" testProxy

does not show the expected result.


However, in most cases this workaround is not feasible.

Comments
Still present in master: https://github.com/openjdk/jdk/blob/fe77250fa450ec803d2818dc90c5bf156521d537/src/java.base/windows/native/libnet/DefaultProxySelector.c#L272
13-07-2022

There is certainly some support for wildcards in nonProxyHosts. There are a few proxy selector tests that verify that ( [1] seems to be the most comprehensive ). The fix for JDK-8170868, provides better integrates with the system proxy configuration. I've added a comment to 7014531. Maybe there is still an issue but it is not clear from 7014531 what that might be. [1] http://hg.openjdk.java.net/jdk/jdk/file/tip/test/jdk/java/net/ProxySelector/B8035158.java
08-11-2018