JDK-6563259 : incorrect handling when including uppercase letter in hostname
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-05-30
  • Updated: 2014-03-14
  • Resolved: 2011-03-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other Other Other JDK 6 JDK 7
5.0u15-revFixed 5.0u16-revFixed 5.0u17Fixed 6u10Fixed 7 b14Fixed
Related Reports
Relates :  
Description
From jdk 5.0, when setting http.ProxyHost/http.nonProxyHosts,
including uppercase in java.net.URL's hostname will lead to incorrect
handling. This can be seen in the following case.

1.Java system properties
http.proxyHost
http.proxyPort
http.nonProxyHosts

2.Including uppercase in hostname when using
  java.net.URL#openConnection to access.

e.g.
Setting "HOST1" at http.nonProxyHosts and calling
java.net.URL#openConnection to access [http://HOST1/].

Setting "HOST2.sample.com" at http.nonProxyHosts and calling
java.net.URL#openConnection to access [http://HOST2.sample.com/].

Below are the snippets from jdk 5.0 and 1.4.2. In jdk 5.0, line 237
transforms the string specified at system property to lower-case. But
the hostname is not changed when being compared in line 246.

In jdk 1.4.2 source, not only the string specified via
nonProxyHosts(line 220), also the compared hostname is converted to
lower-case(line 588).

[5.0 DefaultProxySelector.java]
-----
109     public java.util.List<Proxy> select(URI uri) {
110         if (uri == null) {
111             throw new IllegalArgumentException("URI can't be null.");
112         }
113         String protocol = uri.getScheme();
114         String host = uri.getHost();
115         int port = uri.getPort();
   ...
172         final String proto = protocol;
173         final NonProxyInfo nprop = pinfo;
174         final String urlhost = host;
  ...
233                                             RegexpPool pool = new RegexpPool();
234                                             StringTokenizer st = new StringTokenizer(nphosts, "|", false);
235                                             try {
236                                                 while (st.hasMoreTokens()) {
237                                                     pool.add(st.nextToken().toLowerCase(), Boolean.TRUE);
238                                                 }
239                                             } catch (sun.misc.REException ex) {
240                                             }
241                                             nprop.hostsPool = pool;
242                                             nprop.hostsSource = nphosts;
243                                         }
244                                     }
245                                     if (nprop.hostsPool != null &&
246                                         nprop.hostsPool.match(urlhost) != null) {
247                                         return Proxy.NO_PROXY;
248                                     }
249                                 }
250                             }
-----

[1.4.2 HttpClient.java]
-----
216                     RegexpPool pool = new RegexpPool();
217                     StringTokenizer st = new StringTokenizer(rawList, "|", false);
218                     try {
219                         while (st.hasMoreTokens()) {
220                             pool.add(st.nextToken().toLowerCase(), Boolean.TRUE);
221                         }
222                     } catch (sun.misc.REException ex) {
223                         System.err.println("Error in http.nonProxyHosts system property:  " + ex);
224                     }
  ...
588         String urlHost = url.getHost().toLowerCase();
589         boolean loopback = isLoopback(urlHost);
590
591         if (url.getProtocol().equals("http") ||
592             url.getProtocol().equals("https") ) {
593
594             if ((instProxy != null) && !loopback) {
595                 privilegedOpenServer(instProxy, instProxyPort);
596                 usingProxy = true;
597                 return;
598             }
599
600             String proxyHost = getProxyHost();
601             if ((proxyHost != null) &&
602                 (!(proxyDisabled ||
603                    loopback ||
604                    matchNonProxyHosts(urlHost) ||
605                    matchNonProxyHosts(host)))) {
-----

Comments
EVALUATION Yes, that was an oversight when implementing the DefaultProxySelector. The proposed code change is the right fix.
01-06-2007