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.
This commit is contained in:
sandeep.konchady%sun.com 2005-08-16 23:44:45 +00:00
Родитель 5307a7e218
Коммит 9c0e116e76
2 изменённых файлов: 38 добавлений и 19 удалений

Просмотреть файл

@ -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();
}
}
}

Просмотреть файл

@ -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();
}
}
/**