[
https://issues.apache.org/jira/browse/JENA-1601?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16617532#comment-16617532
]
David Schwingenschlögl commented on JENA-1601:
----------------------------------------------
Thanks for your reply. I was not aware of the warnings generated, but this is a
good point, and was already discussed on the user list, e.g. here:
[https://github.com/apache/jena/pull/133] (my impression is that such change is
likely to be rejected by the community without a very strong argument to back
it up).
Regarding your question for a use case: may I come back to you on that in 1-2
weeks? While I am certain that we had some serious issues back in Jena 2.4
(with all sorts of nasty effects a leaking DB connection has), I am not so firm
with the problems we had when switching to Jena 3.x. I would like to consult a
collegue who may provide such use case (who is currently on vacation).
This would be also the time that I'd kindle the discussion on the users-list
again.
> Make ClosableIterator<T> extend AutoCloseable
> ---------------------------------------------
>
> Key: JENA-1601
> URL: https://issues.apache.org/jira/browse/JENA-1601
> Project: Apache Jena
> Issue Type: Improvement
> Components: Jena
> Affects Versions: Jena 3.8.0
> Reporter: David Schwingenschlögl
> Priority: Minor
>
> The interface org.apache.jena.util.iterator.ClosableIterator<T> defines a
> method public void close(), so the concept of closing is already baked into
> it. The only barrier to using a ClosableIterator (and thus, ExtendedIterator)
> in a try-with-resource block is the missing extension of
> java.lang.AutoCloseable.
> According to API documentation of ClosableIterator, an iterator should be
> closed when not completely exhausted, which may be the case when the block
> consuming the iterator throws an exception, effectively making constructs
> such as this necessary:
> {code:java}
> final ExtendedIterator<Triple> iterator = someGraph.find();
> try {
> while (iterator.hasNext()) {
> // consume iterator, might throw in here
> }
> } finally {
> // Prevent resource leaks
> iterator.close();
> }
> {code}
> This would be better expressed in a try-with-resource-construct:
> {code:java}
> try (final ExtendedIterator<Triple> itrator = someGraph.find()) {
> // consume iterator, might throw in here
> }
> {code}
> From what I can tell, making a ClosableIterator also extend AutoCloseable
> only adds to the usability of Jena's API while keeping source backwards
> compatibility intact.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)