Connection.addConnectionListener() throws an exception if disconnected

I’m having a bit of an issue with the way addConnectionListener() is implemented.

Is there a good reason why it throws an exception if the connection isn’t up yet?

As far as I can tell, it makes much more sense to set up all listeners first, then connect(). If the connection attempt fails immediately, the error will be missed as no listener is attached yet. On the other hand, if a listener is already added, it will stay even if the connection is broken and reconnected later. So there’s no real benefit in denying addConnectionListener() before connect().

Can someony clarify why this check is necessary?

I agree, it doesn’t seem to make that much sense.

Logged in Jira as SMACK-339