-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Returning a copied collection to avoid corrupted iterator by multiple…
… threads Signed-off-by: ntisseyre <[email protected]>
- Loading branch information
Showing
1 changed file
with
13 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]) | ||
|
@@ -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; | ||
} | ||
|
||
} |