Jean-Christophe Collet wrote:
[snip]

What's happening here is that the ProxySelector() is not called to check whether the URLConnection should use a proxy but whether the Socket should use a SOCKS proxy.

Good catch Jessie, I missed that.

I was just about to run the test, no need to now.

-Chris

Hence the endless recursive loop.
If you're going to make network calls from the ProxySelector implementation (which is not recommended), make sure you cover your bases to avoid that kind of problem.
In your case, having select be:
       @Override
       public List<Proxy> select(URI uri) {
if (uri.getScheme().equalsIgnorCase("http")) { // Avoid the "socket://" endless loop....
            try {
//bug here, the java doc say that this will bypass the installed
                 //proxyselector but it doesn't.
                 URL u = new URL("http://www.google.com";);
                 URLConnection conn = u.openConnection(Proxy.NO_PROXY);
                 conn.connect();
             } catch (Exception ex) {
Logger.getLogger(UserProxySelector.class.getName()).log(Level.SEVERE, null, ex);
             }
         }
           return Collections.singletonList(Proxy.NO_PROXY);
       }

I'm not sure this should be considered a bug. But it might be worth it to add a few notes in ProxySelector javadoc to warn against such problems.

Reply via email to