Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Won't Fix
-
Jena 3.8.0
-
None
-
None
Description
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:
final ExtendedIterator<Triple> iterator = someGraph.find(); try { while (iterator.hasNext()) { // consume iterator, might throw in here } } finally { // Prevent resource leaks iterator.close(); }
This would be better expressed in a try-with-resource-construct:
try (final ExtendedIterator<Triple> itrator = someGraph.find()) { // consume iterator, might throw in here }
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.