[
https://issues.apache.org/jira/browse/ZOOKEEPER-2511?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15418090#comment-15418090
]
Abraham Fine edited comment on ZOOKEEPER-2511 at 8/11/16 11:10 PM:
-------------------------------------------------------------------
Simply adding "implements AutoCloseable" adds a compiler warning:
ZooKeeper.java:132: warning: [try] auto-closeable resource ZooKeeper has a
member method close() that could throw InterruptedException Which is referenced
here:
http://docs.oracle.com/javase/7/docs/api/java/lang/AutoCloseable.html#close()
So basically, in classes that implement AutoCloseable, you can't/shouldn't
throw InterruptedException from close(). The fun thing is, we don't actually
need that "throws InterruptedException" (nothing in the method throws an
exception, everything is caught elsewhere in the stack). So I imagine it is
kept there for API compatibility purposes. So my solution was to add a
@SuppressWarnings("try") and a comment.
was (Author: abrahamfine):
Simply adding "implements AutoCloseable" adds a compiler warning:
ZooKeeper.java:132: warning: [try] auto-closeable resource ZooKeeper has a
member method close() that could throw InterruptedException Which is referenced
here:
http://docs.oracle.com/javase/7/docs/api/java/lang/AutoCloseable.html#close()
So basically, in classes that implement AutoCloseable, you can't/shouldn't
throw InterruptedException from close(). The fun thing is, we don't actually
need that "throws InterruptedException" (nothing in the method throws an
exception, everything is caught lower in the stack). So I imagine it is kept
there for API compatibility purposes. So my solution was to add a
@SuppressWarnings("try") and a comment.
> Implement AutoCloseable in ZooKeeper.java
> -----------------------------------------
>
> Key: ZOOKEEPER-2511
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2511
> Project: ZooKeeper
> Issue Type: Improvement
> Reporter: Abraham Fine
> Assignee: Abraham Fine
> Attachments: ZOOKEEPER-2511.patch
>
>
> As a java developer I would like to be able to use try-with-resource blocks
> with ZooKeeper objects in order to make closing sessions easier.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)