[
https://issues.apache.org/jira/browse/JENA-1601?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16614059#comment-16614059
]
Andy Seaborne commented on JENA-1601:
-------------------------------------
It might well be the case that adding it is backwards compatible but that isn't
the full story.
The contract on jena's ClosableIterator isn't the same - it is not "must close"
(as you mention). The case documented in the javadoc of automatic (internal)
close on end of iterator is quite common from what I can determine from the
Jena code itself.
The change will cause a bunch of warnings in application code so while not a
breaking change, it is a change. I tried in on the Jena source code and got
about 100 warnings outside the test suites.
ExtendedIterator is used for both the resource-model API and the node-graph SPI.
Out of curiosity, do you have a use case that requires iterator close? I
believe the close requirement was introduced (a long time ago!) for a
BerkeleyDB backend where DB cursors had to be closed. One consideration is
drop the requirement of close altogether. I simply have no idea whether
closeign is assumed by any usage. The value of try-with-resource is only there
if it is needed is, in practice, application code is obeying the contract.
Personally, I'm neutral on the change. I'd like the community impacted, the
whole user community, to guide the decision.choices here. [~indeterminatus] –
maybe email the users@ list to start the debate?
> 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)