forked from typetools/checker-framework
/
Dataset6Crash.java
57 lines (45 loc) · 1.25 KB
/
Dataset6Crash.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Test case for a WPI crash caused by mismatches between captured type variables
// and the declared type of a field: in particular, the issue is that base.next()
// the next field actually have slightly different types: base.next()'s type is
// a capture that extends T.
import java.util.Iterator;
public class Dataset6Crash {
public static <T> Iterator<T> limit(final Iterator<? extends T> base, final CountingPredicate<?
super T> filter) {
return new Iterator<T>() {
private T next;
private boolean end;
private int index = 0;
public boolean hasNext() {
return true;
}
public T next() {
fetch();
T r = next;
next = null;
return r;
}
private void fetch() {
if (next == null && !end) {
if (base.hasNext()) {
next = base.next();
if (!filter.apply(index++, next)) {
next = null;
end = true;
}
} else {
end = true;
}
}
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
private static class CountingPredicate<T> {
public boolean apply(int i, T next) {
return false;
}
}
}