JDK-7178362 : Socket impls should ignore unsupported proxy types rather than throwing
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 6u30
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2012-06-20
  • Updated: 2016-05-27
  • Resolved: 2015-02-25
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 7 JDK 8 JDK 9
7u80Fixed 8u45Fixed 9 b53Fixed
Related Reports
Duplicate :  
Description
In the case of a "bad" ProxySelector returning proxies of types other than Proxy.Type.SOCKS to the socket impl ( java.net.SocksSocketImpl ) we should just ignore these proxies and try a direct connection, rather than throwing SocketException("Unknown proxy type : XXXX"). This is a confusing Exception and message, and a better alternative is to simply try a direct connection.

Exception in thread "main" java.net.SocketException: Unknown proxy type : HTTP
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:395)
        at java.net.Socket.connect(Socket.java:578)
        at java.net.Socket.connect(Socket.java:527)
        at java.net.Socket.<init>(Socket.java:423)
        at java.net.Socket.<init>(Socket.java:240)
        .......

This issue has been reported on several forums and sites:
  http://www.coderanch.com/t/580126/JNLP-Web-Start/java/SocketException-Unknown-proxy-type-HTTP
  https://forums.oracle.com/forums/thread.jspa?threadID=2385257
  http://stackoverflow.com/questions/2175742/connecting-with-different-proxies-to-specific-addresses

Minimal testcase to demonstrate the problem:
-------------
public class BadProxySelector {
    public static void main(String[] args) throws Exception {
        ProxySelector oldSelector = ProxySelector.getDefault();
        ProxySelector.setDefault(new HTTPProxySelector());
        try {
            try (ServerSocket ss = new ServerSocket(0);
                 Socket s1 = new Socket(ss.getInetAddress(), ss.getLocalPort());
                 Socket s2 = ss.accept()) {
            }
        } finally {
            ProxySelector.setDefault(oldSelector);
        }
    }

    // always returns bogus HTTP proxies
    private static class HTTPProxySelector extends ProxySelector {
        @Override
        public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {}

        @Override
        public List<Proxy> select(URI uri) {
            List<Proxy> proxies = new ArrayList<>();
            proxies.add(new Proxy(Proxy.Type.HTTP,
                                  new InetSocketAddress("localhost", 56789)));
            proxies.add(new Proxy(Proxy.Type.HTTP,
                                  new InetSocketAddress("localhost", 56784)));
            return proxies;
        }
    }
}
-------------

Comments
SQE OK to take the fix to PSU15_02 based on 7u85 nightly testing
02-03-2015

This is currently a P4 and does not appear to be critical for JDK 8. I'm temporarily setting the fixVersion to tbd_major until there is a definite plan for this one.
13-09-2013

EVALUATION This is a confusing Exception and message, and a better alternative is to try a direct connection.
20-06-2012