Skip to content

Commit

Permalink
Returning a copied collection to avoid corrupted iterator by multiple…
Browse files Browse the repository at this point in the history
… threads

Signed-off-by: ntisseyre <[email protected]>
  • Loading branch information
ntisseyre committed Feb 22, 2024
1 parent 1530f0a commit bfa75db
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
package org.janusgraph.graphdb.transaction.addedrelations;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import org.janusgraph.graphdb.internal.InternalRelation;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
* @author Matthias Broecheler ([email protected])
Expand All @@ -37,11 +41,18 @@ public synchronized boolean remove(final InternalRelation relation) {

@Override
public synchronized Iterable<InternalRelation> getView(final Predicate<InternalRelation> filter) {
return super.getView(filter);
return copyView(super.getView(filter));
}

@Override
public synchronized Collection<InternalRelation> getAll() {
return super.getAll();
return new ArrayList<>(super.getAll());
}

private Iterable<InternalRelation> copyView(Iterable<InternalRelation> currentView) {
ArrayList<InternalRelation> view = new ArrayList<>();
Iterables.addAll(view, currentView);
return view;
}

}

0 comments on commit bfa75db

Please sign in to comment.