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

ContextAwareRepository StackOverflowError when adding model #4826

Closed
domkun opened this issue Oct 27, 2023 · 1 comment · Fixed by #4827
Closed

ContextAwareRepository StackOverflowError when adding model #4826

domkun opened this issue Oct 27, 2023 · 1 comment · Fixed by #4827
Assignees
Labels
🐞 bug issue is a bug
Milestone

Comments

@domkun
Copy link
Contributor

domkun commented Oct 27, 2023

Current Behavior

Using the ContextAwareRepository and calling connection.add(model) results in a StackOverflowError in

at org.eclipse.rdf4j.repository.RepositoryConnection.add(RepositoryConnection.java:988)
at org.eclipse.rdf4j.repository.contextaware.ContextAwareConnection.add(ContextAwareConnection.java:330)

Expected Behavior

Model gets added to repository.

Steps To Reproduce

To reproduce use the following code:

import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.impl.DynamicModelFactory;
import org.eclipse.rdf4j.model.util.Values;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.contextaware.ContextAwareRepository;
import org.eclipse.rdf4j.repository.sail.SailRepository;
import org.eclipse.rdf4j.sail.memory.MemoryStore;

class Scratch {
    public static void main(String[] args) {
        ContextAwareRepository ctxAwareRepo = new ContextAwareRepository(new SailRepository(new MemoryStore()));
        ctxAwareRepo.setInsertContext(Values.iri("some:default"));
        ctxAwareRepo.setReadContexts(Values.iri("some:default"));

        works(ctxAwareRepo);
        fails(ctxAwareRepo);
    }

    public static void fails(Repository repo) {
        try (RepositoryConnection conn = repo.getConnection()) {
            Model model = new DynamicModelFactory().createEmptyModel();
            model.add(Values.iri("some:iri"), Values.iri("some:p"), Values.literal("some"));
            conn.add(model);
            conn.getStatements(null, null, null).forEach(System.out::println);
        }
    }

    public static void works(Repository repo) {
        try (RepositoryConnection conn = repo.getConnection()) {
            conn.add(Values.iri("some:iri"), Values.iri("some:p"), Values.literal("some"));
            conn.getStatements(null, null, null).forEach(System.out::println);
        }
    }
}

Version

4.3.7

Are you interested in contributing a solution yourself?

None

Anything else?

No response

@domkun domkun added the 🐞 bug issue is a bug label Oct 27, 2023
@domkun
Copy link
Contributor Author

domkun commented Oct 30, 2023

I think the problem is located here:

super.add(new ConvertingIteration<Statement, Statement, E>(statementIter) {

Casting the ConvertingIteration to Iteration<? extends Statement, E> fixes the problem, however I currently struggle to write a sane test for this. I added a PR anyways, maybe it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug issue is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants