File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
crud/src/main/java/com/redhat/lightblue/crud Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change 27
27
public class ListDocumentStream <T > implements DocumentStream <T > {
28
28
29
29
private final List <T > documents ;
30
- private final Iterator <T > itr ;
30
+ private Iterator <T > itr ;
31
31
32
32
public ListDocumentStream (List <T > list ) {
33
33
this .documents =list ;
34
- this .itr =documents .iterator ();
35
34
}
36
35
37
36
/**
@@ -43,11 +42,19 @@ public List<T> getDocuments() {
43
42
44
43
@ Override
45
44
public boolean hasNext () {
45
+ // Lazy initialization, don't get the iterator until the last
46
+ // moment. This is to protect against concurrent modification
47
+ // exceptions if the list is modified between the creation of
48
+ // the iterator and the actual iteration
49
+ if (itr ==null )
50
+ itr =documents .iterator ();
46
51
return itr .hasNext ();
47
52
}
48
53
49
54
@ Override
50
55
public T next () {
56
+ if (itr ==null )
57
+ itr =documents .iterator ();
51
58
return itr .next ();
52
59
}
53
60
You can’t perform that action at this time.
0 commit comments