Skip to content

Commit 65bed64

Browse files
committedJan 13, 2021
8253635: Implement toString() for SSLEngineImpl
Reviewed-by: coffeys, wetmore
1 parent c6d798c commit 65bed64

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed
 

‎src/java.base/share/classes/sun/security/ssl/SSLEngineImpl.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1089,6 +1089,15 @@ public boolean useDelegatedTask() {
10891089
return true;
10901090
}
10911091

1092+
@Override
1093+
public String toString() {
1094+
return "SSLEngine[" +
1095+
"hostname=" + getPeerHost() +
1096+
", port=" + getPeerPort() +
1097+
", " + conContext.conSession + // SSLSessionImpl.toString()
1098+
"]";
1099+
}
1100+
10921101
/*
10931102
* Depending on whether the error was just a warning and the
10941103
* handshaker wasn't closed, or fatal and the handshaker is now

‎src/java.base/share/classes/sun/security/ssl/SSLSocketImpl.java

+20-23
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import java.net.Socket;
3636
import java.net.SocketAddress;
3737
import java.net.SocketException;
38-
import java.net.UnknownHostException;
3938
import java.nio.ByteBuffer;
4039
import java.util.List;
4140
import java.util.concurrent.TimeUnit;
@@ -135,7 +134,7 @@ public final class SSLSocketImpl
135134
* if appropriate.
136135
*/
137136
SSLSocketImpl(SSLContextImpl sslContext, String peerHost,
138-
int peerPort) throws IOException, UnknownHostException {
137+
int peerPort) throws IOException {
139138
super();
140139
this.sslContext = sslContext;
141140
HandshakeHash handshakeHash = new HandshakeHash();
@@ -179,7 +178,7 @@ public final class SSLSocketImpl
179178
*/
180179
SSLSocketImpl(SSLContextImpl sslContext,
181180
String peerHost, int peerPort, InetAddress localAddr,
182-
int localPort) throws IOException, UnknownHostException {
181+
int localPort) throws IOException {
183182
super();
184183
this.sslContext = sslContext;
185184
HandshakeHash handshakeHash = new HandshakeHash();
@@ -1406,11 +1405,9 @@ private int readHandshakeRecord() throws IOException {
14061405
conContext.isNegotiated) {
14071406
return 0;
14081407
}
1409-
} catch (SSLException ssle) {
1410-
throw ssle;
1411-
} catch (InterruptedIOException iioe) {
1408+
} catch (SSLException | InterruptedIOException ssle) {
14121409
// don't change exception in case of timeouts or interrupts
1413-
throw iioe;
1410+
throw ssle;
14141411
} catch (IOException ioe) {
14151412
throw new SSLException("readHandshakeRecord", ioe);
14161413
}
@@ -1471,17 +1468,11 @@ private ByteBuffer readApplicationRecord(
14711468
buffer.position() > 0) {
14721469
return buffer;
14731470
}
1474-
} catch (SSLException ssle) {
1475-
throw ssle;
1476-
} catch (InterruptedIOException iioe) {
1471+
} catch (SSLException | InterruptedIOException ssle) {
14771472
// don't change exception in case of timeouts or interrupts
1478-
throw iioe;
1473+
throw ssle;
14791474
} catch (IOException ioe) {
1480-
if (!(ioe instanceof SSLException)) {
1481-
throw new SSLException("readApplicationRecord", ioe);
1482-
} else {
1483-
throw ioe;
1484-
}
1475+
throw new SSLException("readApplicationRecord", ioe);
14851476
}
14861477
}
14871478

@@ -1738,19 +1729,25 @@ public void shutdown() throws IOException {
17381729
}
17391730

17401731
try {
1741-
if (conContext.isInputCloseNotified) {
1742-
// Close the connection, no wait for more peer response.
1743-
closeSocket(false);
1744-
} else {
1745-
// Close the connection, may wait for peer close_notify.
1746-
closeSocket(true);
1747-
}
1732+
// If conContext.isInputCloseNotified is false, close the
1733+
// connection, no wait for more peer response. Otherwise,
1734+
// may wait for peer close_notify.
1735+
closeSocket(!conContext.isInputCloseNotified);
17481736
} finally {
17491737
tlsIsClosed = true;
17501738
}
17511739
}
17521740
}
17531741

1742+
@Override
1743+
public String toString() {
1744+
return "SSLSocket[" +
1745+
"hostname=" + getPeerHost() +
1746+
", port=" + getPeerPort() +
1747+
", " + conContext.conSession + // SSLSessionImpl.toString()
1748+
"]";
1749+
}
1750+
17541751
private void closeSocket(boolean selfInitiated) throws IOException {
17551752
if (SSLLogger.isOn && SSLLogger.isOn("ssl")) {
17561753
SSLLogger.fine("close the SSL connection " +

0 commit comments

Comments
 (0)
Please sign in to comment.