am 17f43736: Merge "Fix for test_SSLSocket_HandshakeCompletedListener_RuntimeException"

* commit '17f43736c471947fcec58d9035a47190ec062884':
  Fix for test_SSLSocket_HandshakeCompletedListener_RuntimeException
diff --git a/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java b/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java
index 7ce8727..fcbb0e4 100644
--- a/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java
+++ b/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java
@@ -19,6 +19,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.lang.Thread.UncaughtExceptionHandler;
 import java.lang.reflect.Method;
 import java.net.InetSocketAddress;
 import java.net.ServerSocket;
@@ -494,7 +495,22 @@
         c.close();
     }
 
+    private static final class TestUncaughtExceptionHandler implements UncaughtExceptionHandler {
+        Throwable actualException;
+        @Override public void uncaughtException(Thread thread, Throwable ex) {
+            assertNull(actualException);
+            actualException = ex;
+        }
+    }
+
     public void test_SSLSocket_HandshakeCompletedListener_RuntimeException() throws Exception {
+        final Thread self = Thread.currentThread();
+        final UncaughtExceptionHandler original = self.getUncaughtExceptionHandler();
+
+        final RuntimeException expectedException = new RuntimeException("expected");
+        final TestUncaughtExceptionHandler test = new TestUncaughtExceptionHandler();
+        self.setUncaughtExceptionHandler(test);
+
         final TestSSLContext c = TestSSLContext.create();
         final SSLSocket client = (SSLSocket)
                 c.clientContext.getSocketFactory().createSocket(c.host, c.port);
@@ -509,7 +525,7 @@
         executor.shutdown();
         client.addHandshakeCompletedListener(new HandshakeCompletedListener() {
             public void handshakeCompleted(HandshakeCompletedEvent event) {
-                throw new RuntimeException("RuntimeException from handshakeCompleted");
+                throw expectedException;
             }
         });
         client.startHandshake();
@@ -517,6 +533,9 @@
         client.close();
         server.close();
         c.close();
+
+        assertSame(expectedException, test.actualException);
+        self.setUncaughtExceptionHandler(original);
     }
 
     public void test_SSLSocket_getUseClientMode() throws Exception {