Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphTxn.find().forEachRemaining does not close the iterator. #2197

Closed
afs opened this issue Jan 15, 2024 · 2 comments · Fixed by #2199
Closed

GraphTxn.find().forEachRemaining does not close the iterator. #2197

afs opened this issue Jan 15, 2024 · 2 comments · Fixed by #2199
Assignees
Labels
bug Jena5 Changes relating to Jena5

Comments

@afs
Copy link
Member

afs commented Jan 15, 2024

Version

5.0.0 development

What happened?

GraphTxn.find returns an etxended iterator that does not get closed properly if exhaused by Iterator.forEachRemaining.

WrappedGraph.forEachRemaining call the wrapped class directly.

Relevant output and stacktrace

public static void main(String... args) {
        Graph g = new GraphTxn();
        ExtendedIterator<Triple> iter = g.find();
        iter.toList();
        //iter.close();
        g.add(SSE.parseTriple("(:s :p :o)"));
    }

Are you interested in making a pull request?

Yes

@afs
Copy link
Member Author

afs commented Jan 15, 2024

GraphTxn.toList uses ExtendedIterator.forEachRemaining which in WrappedIterator calls the wrapped class and so bypasses GraphTxn.IteratorTxn.hasNext.

ExtendedIterators are best used as: try { ... } finally { iter.close(); } in case the action throws an unexpected exception.

If NiceIterator.asList, which is the code for iter.toList() called forEach, which does call close, instead of forEachRemaining.

The forEachRemaining case still needs fixing.

@afs afs self-assigned this Jan 15, 2024
@afs afs added the Jena5 Changes relating to Jena5 label Jan 15, 2024
@afs
Copy link
Member Author

afs commented Jan 15, 2024

See also #2086, which backports a Jena5 fix to the Jena4 branch.

afs added a commit to afs/jena that referenced this issue Jan 16, 2024
afs added a commit to afs/jena that referenced this issue Jan 16, 2024
@afs afs closed this as completed in #2199 Jan 17, 2024
cnanjo pushed a commit to fhircat/jena that referenced this issue Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Jena5 Changes relating to Jena5
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant