You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by Abraham Fine <ab...@abrahamfine.com> on 2016/08/25 17:44:20 UTC

Implementation of AutoCloseable in ZooKeeper.java

Hello-

Recently I created and uploaded a patch for ZOOKEEPER-2511. This jira implements the AutoCloseable interface in ZooKeeper.java which would allow developers to use try-with-resources with zookeeper. I think this will help prevent our users from forgetting to close sessions.

Without repeating the contents of the JIRA discussion I had with Michael Han here, there is an issue which revolves around the close() method having “throws InterruptedException” in its signature despite never actually throwing that exception (I assume this is for API compatibility purposes). If close() throws an InterruptedException and AutoCloseable is implemented there can be some undefined behavior (and the java compiler will output a warning).

Since we never actually throw that exception, my solution was to ignore the compiler warning and leave an explanation in a comment.

Please take a look here: https://issues.apache.org/jira/browse/ZOOKEEPER-2511 <https://issues.apache.org/jira/browse/ZOOKEEPER-2511> and let me know if there is a better way to solve the problem.

Thanks,
Abe

Re: Implementation of AutoCloseable in ZooKeeper.java

Posted by Abraham Fine <ab...@abrahamfine.com>.
Hi-

It looks like ZOOKEEPER-2511 has received a couple of comments, both seem to agree with what the patch currently does.

Any possibility of getting this committed?

Thanks,
Abe

> On Aug 25, 2016, at 10:44, Abraham Fine <ab...@abrahamfine.com> wrote:
> 
> Hello-
> 
> Recently I created and uploaded a patch for ZOOKEEPER-2511. This jira implements the AutoCloseable interface in ZooKeeper.java which would allow developers to use try-with-resources with zookeeper. I think this will help prevent our users from forgetting to close sessions.
> 
> Without repeating the contents of the JIRA discussion I had with Michael Han here, there is an issue which revolves around the close() method having “throws InterruptedException” in its signature despite never actually throwing that exception (I assume this is for API compatibility purposes). If close() throws an InterruptedException and AutoCloseable is implemented there can be some undefined behavior (and the java compiler will output a warning).
> 
> Since we never actually throw that exception, my solution was to ignore the compiler warning and leave an explanation in a comment.
> 
> Please take a look here: https://issues.apache.org/jira/browse/ZOOKEEPER-2511 <https://issues.apache.org/jira/browse/ZOOKEEPER-2511> and let me know if there is a better way to solve the problem.
> 
> Thanks,
> Abe