I noticed all or most of our tests for AblyRealtime have the try-catch-finally pattern, becuase the instantiated AblyRealtime objects need to be closed. I suspect that also in "real" usage, the object has to be closed when its no longer needed.
In order to simplify things, this class should implement Autocloseable and be used in try-with-resources, which was introduced in Java 7. Then, the code can be simplified a lot for our clients and also in our tests. Instead of this:
try {
AblyRealtime ably = ...
} catch (AblyException ex) {
fail(...);
} finally {
ably.close();
}
we will have this:
try (AblyRealtime ably = ...) {
...
} // we don't care about the exception anymore
//since the test will fail automatically and log
//the exception anyway, if it is thrown.
Note that this change will not affect backwards compatibility!
I noticed all or most of our tests for
AblyRealtimehave thetry-catch-finallypattern, becuase the instantiatedAblyRealtimeobjects need to be closed. I suspect that also in "real" usage, the object has to be closed when its no longer needed.In order to simplify things, this class should implement Autocloseable and be used in
try-with-resources, which was introduced in Java 7. Then, the code can be simplified a lot for our clients and also in our tests. Instead of this:we will have this:
Note that this change will not affect backwards compatibility!