Bug Id: 304195

Added try/catch block around the method calls within toString().  Calls
such as getInetAddress(), getPort() etc does not check if the socket is
closed, and when applications use toString() on a closed socket, there
is an uncaught exception.


git-svn-id: svn://10.0.0.236/trunk@177919 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
sandeep.konchady%sun.com 2005-08-16 23:44:45 +00:00
parent 7908965789
commit 60860ee691
2 changed files with 38 additions and 19 deletions

View File

@ -434,15 +434,23 @@ public class SSLServerSocket extends java.net.ServerSocket {
}
/**
* Returns the addresses and ports of this socket.
* Returns the addresses and ports of this socket
* or an error message if the socket is not in a valid state.
*/
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append("SSLServerSocket[addr=");
buf.append(getInetAddress());
buf.append(",port=0,localport=");
buf.append(getLocalPort());
buf.append("]");
return buf.toString();
try {
InetAddress inetAddr = getInetAddress();
int localPort = getLocalPort();
StringBuffer buf = new StringBuffer();
buf.append("SSLServerSocket[addr=");
buf.append(inetAddr);
buf.append(",localport=");
buf.append(localPort);
buf.append("]");
return buf.toString();
} catch (Exception e) {
return "Exception caught in toString(): " + e.getMessage();
}
}
}

View File

@ -818,19 +818,30 @@ public class SSLSocket extends java.net.Socket {
throws SocketException;
/**
* Returns the addresses and ports of this socket.
* Returns the addresses and ports of this socket
* or an error message if the socket is not in a valid state.
*/
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append("SSLSocket[addr=");
buf.append(getInetAddress());
buf.append(getLocalAddress());
buf.append(",port=");
buf.append(getPort());
buf.append(",localport=");
buf.append(getLocalPort());
buf.append("]");
return buf.toString();
try {
InetAddress inetAddr = getInetAddress();
InetAddress localAddr = getLocalAddress();
int port = getPort();
int localPort = getLocalPort();
StringBuffer buf = new StringBuffer();
buf.append("SSLSocket[addr=");
buf.append(inetAddr);
buf.append(",localaddr=");
buf.append(localAddr);
buf.append(",port=");
buf.append(port);
buf.append(",localport=");
buf.append(localPort);
buf.append("]");
return buf.toString();
} catch (Exception e) {
return "Exception caught in toString(): " + e.getMessage();
}
}
/**