JDK-6737819 : sun.misc.net.DefaultProxySelector doesn't use proxy setting to localhost
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 6
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2008-08-15
  • Updated: 2017-05-16
  • Resolved: 2009-09-26
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 6 JDK 7
6u14Fixed 7 b73Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Linux ukp79266 2.6.9-55.0.0.0.2.ELsmp #1 SMP Wed May 2 14:59:56 PDT 2007 i686 i686 i386 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
The DefaultProxySelector implementation will never use a proxy for a request to "localhost" even if the invoker has specifically speficied that no host will be excluded.

This is a problem when trying to connect to a sever on the current machine whilst trying to use some kind of http packet monitoring tool. (In this case the HTTP Analyzer from JDeveloper)

So in this case the url to the web service I am trying to connect with is "http://localhost:7101/..." and the name of the proxy is "localhost:8898". The parameter passed into the running client are:

-Dhttp.proxyHost = localhost
-Dhttp.proxyPort = 8988
-Dhttp.nonProxyHosts =

I would have hoped that the default proxy selector would honor the fact I have requested an empty ingore list. Looking at the code it appears that the test for local host is performed well before the property is even queried.

The localhost test should only be applied if and when the nonProxyHosts property for the given protocol is null.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Configure a http proxying tools such as tcp mon on the local machine
2. Run web service on machine
3. Run java client for web service with http proxy properties set to use the http proxying tool and set up to connect to a local host URL.

No traffic will be sent the way of the monitor tool. It will never be proxied.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
When nonProxyedHosts is defiend as being blank even localhost should be proxied.
ACTUAL -
All request to localhost go un proxied.

REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
Put in place own ProxySelector; but this doesn't allow a developer to test software without making modifications.

Comments
EVALUATION Actually, we will change the behaviour in JDK 7 as it was introduced by mistake while fixing another bug.
20-02-2009

EVALUATION As pointed out in the comments, the reason localhost or explicit loopback addresses are excluded from proxying is not quite a bug, it's on purpose. Asking a proxy to connect to 127.0.0.1 for instance is often seen as a security risk and doesn't make much sense in the general case. In the case of the DefaultProxySelector it's also a question of backward compatibility. See CR 4924226 for details. However, we will see if we can use http.nonProxyHosts system property (or another existing one) to change that behavior when set with a special value.
05-12-2008

WORK AROUND When accessing the URL use "http://localhost.localdomain:7101/..." instead of just "http://localhost:7101/..."
05-09-2008