BasicClientHandler.isOpen() can throw SocketException even though it says it can't

12 views
Skip to first unread message

Dwayne Smurdon

unread,
Jun 1, 2014, 5:11:13 PM6/1/14
to quick...@googlegroups.com
I just posted to https://code.google.com/p/quickserver/issues/detail?id=4, but I can't tell if that's monitored or not, since it looks like the last issue is over 2 years ago. :)

Below is the post/issue:


Hello,

I have not done extensive testing/debugging, but I peaked at the code and I think there is a bug.  isOpen() says it doesn't throw a SocketException.  However, if you look at it's implementation, it does in fact call isConnected() which throws the Exception, and I never get the 'false' returned to me.

I think you'll need to surround it with a try/catch block and handle that exception if you don't want it to throw one (even if indirectly).

The way I can replicate this error is I keep a ConcurrentHashMap<String, ClientHandler>....and then I manually disconnect those clients.  When I iterate that ConcurrentHashMap, and call isOpen(), I want to move it from one map to the other if it is NOT open.  

Below is some of the relevant code from org.quickserver.net.server.impl.BasicClientHandler

-Dwayne

	/**
	 * Checks if the client is still connected.
	 * @exception SocketException if Socket is not open.
	 * @since 1.4.5
	 */
	public boolean isConnected() throws SocketException {
		if(isOpen()==false)
			throw new SocketException("Connection is no more open!");
		else
			return true;
	}

	/**
	 * Checks if the client is still connected and if socket is open. This is same as isConnected() 
     * but does not throw SocketException.
	 * @since 1.4.6
	 */
	public boolean isOpen() {
		if(lost==true || socket==null || socket.isConnected()==false || socket.isClosed()==true)
			return false;
		else
			return true;
	}

Akshath

unread,
Jun 3, 2014, 2:01:57 PM6/3/14
to quick...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages