United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6737819 sun.misc.net.DefaultProxySelector doesn't use proxy setting to localhost
JDK-6737819 : sun.misc.net.DefaultProxySelector doesn't use proxy setting to localhost

Details
Type:
Bug
Submit Date:
2008-08-15
Status:
Resolved
Updated Date:
2013-09-19
Project Name:
JDK
Resolved Date:
2009-09-26
Component:
core-libs
OS:
linux
Sub-Component:
java.net
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports
Backport:
Relates:
Relates:
Relates:

Sub Tasks

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

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.
                                     
2008-12-05
WORK AROUND

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

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



Hardware and Software, Engineered to Work Together