title: SSL Connection Handshake Java 8 not working
body: <p>I have the following simple code to establish an SSL connection.</p>
  <pre><code>public static void main(String[] args) throws IOException {
      
      System.setProperty(&quot;javax.net.debug&quot;, &quot;ALL&quot;);
      System.setProperty(&quot;java.net.useSystemProxies&quot;, &quot;true&quot;);
      
      URL url = new URL(&quot;https://google.com&quot;);
      URLConnection con = url.openConnection();
      try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()))) {
          String line = null;
          while ((line = br.readLine()) != null) {
              System.out.println(line);
          }
      }
  }
  </code></pre>
  <p>If I run this code under Java 8 it doesn't work. It stops at starting the SSL Handshake with a <code>java.net.SocketException: Connection reset</code>.</p>
  <blockquote>
  <p>main, WRITE: TLSv1.2 Handshake, length = 214 main, waiting for
  close_notify or alert: state 1 Exception in thread &quot;main&quot;
  java.net.SocketException: Connection reset    at
  java.net.SocketInputStream.read(SocketInputStream.java:209)   at
  java.net.SocketInputStream.read(SocketInputStream.java:141)   at
  sun.security.ssl.InputRecord.readFully(InputRecord.java:465)  at
  sun.security.ssl.InputRecord.read(InputRecord.java:503)   at
  sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)     at
  sun.security.ssl.SSLSocketImpl.waitForClose(SSLSocketImpl.java:1769)
  at
  sun.security.ssl.HandshakeOutStream.flush(HandshakeOutStream.java:124)
  at sun.security.ssl.Handshaker.kickstart(Handshaker.java:1020)  at
  sun.security.ssl.SSLSocketImpl.kickstartHandshake(SSLSocketImpl.java:1487)
  at
  sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1351)
  at
  sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
  at
  sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
  at
  sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
  at
  sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
  at
  sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1512)
  at
  sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)
  at
  sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
  at com.hlcl.exp.Main.main(Main.java:18) main, Exception while waiting
  for close java.net.SocketException: Connection reset main, handling
  exception: java.net.SocketException: Connection reset main, SEND
  TLSv1.2 ALERT:  fatal, description = unexpected_message main, WRITE:
  TLSv1.2 Alert, length = 2 main, Exception sending alert:
  java.net.SocketException: Connection reset by peer: socket write error
  main, called closeSocket()</p>
  </blockquote>
  <p>If I execute the same code in a Java 10 environment it works.</p>
  <p>I have checked the proxy which is detected by java. Under Java 8 a DIRECT (no proxy) connection is detected. With Java 10 the following proxy settings are detected.</p>
  <blockquote>
  <p>proxy type: HTTP</p>
  </blockquote>
  <blockquote>
  <p>proxy hostname:
  ipv4.xxx.xxx.xxx.com</p>
  </blockquote>
  <blockquote>
  <p>proxy port: 8081</p>
  </blockquote>
  <p>If I remove <code>System.setProperty(&quot;java.net.useSystemProxies&quot;, &quot;true&quot;);</code> or set it to false it also not work with Java 10. But setting the proxy settings via the system properties is not working.</p>