On Fri, 7 Apr 2023, at 11:54, Matthew Nguyen via rdf4j-dev wrote:
Think some context may have been lost along the way but I'm referring to models.getstatements() returning an iterator that is not AutoCloseable.
Ok this seems to be the crux of the thing.
First of all, a nitpick: model.getStatements does not return an iterator. It returns an Iterable. The intent is that it can be used in a for-each loop.
Implementations of Iterable are things like Model, or HashSet, or ArrayList. None of these implement AutoCloseable. If you are suggesting that getStatements should return an AutoCloseable, then Model itself should also be AutoCloseable, for consistency's sake.
It would be technically possible to do this of course, but it breaks one of the main design motivations for the Model API: ease of use for people famiiiar with the Java Collection framework. Suddenly their IDEs will start screaming at them at every point where they're creating/accessing a model that they have potential resource leaks and should wrap things in try-with-resources blocks, when in 99.9% of use cases there is no need for this, as all model implementation we provide for use in third party code are in-memory collections, and not database or file-backed.
Cheers,
Jeen