Skip to content

Commit 5b8fa3f

Browse files
committed
Java: Add test for Stream.collect.
1 parent 8c7b6d6 commit 5b8fa3f

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import java.util.*;
2+
import java.util.stream.*;
3+
4+
public class A {
5+
String source() { return "source"; }
6+
7+
void sink(Object o) { }
8+
9+
void m() {
10+
String[] xs = new String[] { source() };
11+
Stream<String> s = Arrays.stream(xs);
12+
13+
sink(s.collect(Collectors.maxBy(null)).get()); // $ hasValueFlow
14+
sink(s.collect(Collectors.minBy(null)).get()); // $ hasValueFlow
15+
sink(s.collect(Collectors.toCollection(null)).iterator().next()); // $ hasValueFlow
16+
sink(s.collect(Collectors.toList()).get(0)); // $ hasValueFlow
17+
sink(s.collect(Collectors.toSet()).iterator().next()); // $ hasValueFlow
18+
sink(s.collect(Collectors.toUnmodifiableList()).get(0)); // $ hasValueFlow
19+
sink(s.collect(Collectors.toUnmodifiableSet()).iterator().next()); // $ hasValueFlow
20+
21+
// we don't attempt to cover weird things like this:
22+
sink(s.collect(true ? Collectors.toList() : null).get(0)); // $ MISSING: hasValueFlow
23+
24+
sink(s.collect(Collectors.joining())); // $ hasTaintFlow
25+
26+
sink(s.collect(Collectors.groupingBy(null)).get(null).get(0)); // $ hasValueFlow
27+
sink(s.collect(Collectors.groupingByConcurrent(null)).get(null).get(0)); // $ hasValueFlow
28+
sink(s.collect(Collectors.partitioningBy(null)).get(null).get(0)); // $ hasValueFlow
29+
}
30+
}

java/ql/test/library-tests/dataflow/stream-collect/test.expected

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import TestUtilities.InlineFlowTest

0 commit comments

Comments
 (0)