sun/net/www/protocol/https/HttpsURLConnection/ReadTimeout.java adapts to new exception hierarchy JDK-8145252-TLS13-branch
authorjjiang
Wed, 23 May 2018 17:02:13 +0800
branchJDK-8145252-TLS13-branch
changeset 56595 fa746939d740
parent 56594 99e0f3f3f0e4
child 56599 137a16d6d987
sun/net/www/protocol/https/HttpsURLConnection/ReadTimeout.java adapts to new exception hierarchy
test/jdk/sun/net/www/protocol/https/HttpsURLConnection/ReadTimeout.java
--- a/test/jdk/sun/net/www/protocol/https/HttpsURLConnection/ReadTimeout.java	Tue May 22 21:46:47 2018 -0700
+++ b/test/jdk/sun/net/www/protocol/https/HttpsURLConnection/ReadTimeout.java	Wed May 23 17:02:13 2018 +0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -175,9 +175,9 @@
 
                 throw new Exception(
                         "system property timeout configuration does not work");
-            } catch (SocketTimeoutException stex) {
+            } catch (SSLException | SocketTimeoutException ex) {
                 System.out.println("Got expected timeout exception for " +
-                        "system property timeout configuration: " + stex);
+                        "system property timeout configuration: " + getCause(ex));
             } finally {
                 done();
                 http.disconnect();
@@ -196,9 +196,9 @@
 
                 throw new Exception(
                         "HttpsURLConnection.setReadTimeout() does not work");
-            } catch (SocketTimeoutException stex) {
+            } catch (SSLException | SocketTimeoutException ex) {
                 System.out.println("Got expected timeout exception for " +
-                        "HttpsURLConnection.setReadTimeout(): " + stex);
+                        "HttpsURLConnection.setReadTimeout(): " + getCause(ex));
             } finally {
                 done();
                 http.disconnect();
@@ -208,6 +208,20 @@
         }
     }
 
+    private Exception getCause(Exception ex) {
+        Exception cause = null;
+        if (ex instanceof SSLException) {
+            cause = (Exception) ex.getCause();
+            if (!(cause instanceof SocketTimeoutException)) {
+                throw new RuntimeException("Unexpected cause", cause);
+            }
+        } else {
+            cause = ex;
+        }
+
+        return cause;
+    }
+
     static class NameVerifier implements HostnameVerifier {
         public boolean verify(String hostname, SSLSession session) {
             return true;