[ https://issues.apache.org/jira/browse/ZOOKEEPER-2511?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15418110#comment-15418110 ]
Michael Han commented on ZOOKEEPER-2511: ---------------------------------------- bq. 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. Regarding this, should we try fix the interface? Dig a little bit of history and the change is made in ZOOKEEPER-63 where we moved a chunk of code that could throw InterruptedException from ZooKeeper::close into a try catch block of ClientCnx::close which catches the InterruptedException. {code} RequestHeader h = new RequestHeader(); h.setType(ZooDefs.OpCode.closeSession); cnxn.submitRequest(h, null, null, null); {code} In ClientCnx::close: {code} try { RequestHeader h = new RequestHeader(); h.setType(ZooDefs.OpCode.closeSession); submitRequest(h, null, null, null); } catch (InterruptedException e) { // ignore, close the send/event threads } finally { disconnect(); } {code} I see a couple of solutions: * Don't catch InterruptedException in ClientCnx::close. No signature change to ZooKeeper::close. * Just remove throw InterruptedException from ZooKeeper::close, because it does not throw such exception. Client code that catching this exception will need update to remove the catch, so this is not backward compatible. * Do nothing with regards to fix the interface, and use the solution proposed in this patch to suppress warning. > 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)