JDK-8145732 : Duplicate entry in http.nonProxyHosts will ignore subsequent entries
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7u45,8
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2015-10-01
  • Updated: 2017-11-29
  • Resolved: 2016-08-12
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.
JDK 8 JDK 9
8u152Fixed 9 b132Fixed
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]. Should also apply to other OS

A DESCRIPTION OF THE PROBLEM :
When using an http proxy (with -Dhttp.proxyHost) and specifying proxy exceptions (-Dhttp.nonProxyHosts) there is a bug when an entry in the list of nonProxyHosts is a duplicate.

The reason is in the code of sun.net.spi.DefaultProxySelector at line 265:

try {
   while (st.hasMoreTokens()) {
      pool.add(st.nextToken().toLowerCase(), Boolean.TRUE);
   }
} catch (sun.misc.REException ex) {
}

If a duplicate item is added to the pool, an REException is thrown and silently discarded. Thus, all remaining items will not be added to the pool. A possible fix for this is, to add an additional paramter to the add method in line 265:

      pool.add(st.nextToken().toLowerCase(), Boolean.TRUE, true);

This will skip the exception.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Set nonProxyHosts with duplicate items. E.g.:

-Dhttp.nonProxyHosts=example.com|example.com|myproxyexception.com



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The domain myproxyexception.com should not be called through the proxy.
ACTUAL -
The domain myproxyexception.com is called through the proxy.

REPRODUCIBILITY :
This bug can be reproduced always.


Comments
Following are the results of executing the attached test case: JDK 7u40 - Fail JDK 8u60 - Fail JDK 8u72 - Fail JDK 9ea b93 - Pass Following is the output on JDK 8 and 7 versions: Is connection using proxy? true Sending 'GET' request to URL : https://bugs.openjdk.java.net Response Code : 200 - HTTP @ xxx ---------------------------------------------------------------------------- Output on JDK 9 : Is connection using proxy? false Sending 'GET' request to URL : https://bugs.openjdk.java.net Response Code : 200 - DIRECT
18-12-2015

This issue was fixed in the jdk9 with the fix for JDK-8035158. However, it seems to be still there in jdk8 and earlier.
15-10-2015