forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectionTest.java
More file actions
52 lines (46 loc) · 1.66 KB
/
CollectionTest.java
File metadata and controls
52 lines (46 loc) · 1.66 KB
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
import java.util.*;
public class CollectionTest {
// should not be flagged since l1 is public
public List<Integer> l1 = new ArrayList<Integer>();
// should not be flagged since l2 is a parameter
public Set<Integer> m(List<Integer> l2) {
l2.add(23);
// should not be flagged since it is assigned an existing collection
Collection<Integer> l3 = l2;
// should not be flagged since it is assigned an existing collection
Collection<Integer> l33;
l33 = l2;
// should not be flagged since it is returned
Set<Integer> s1 = new LinkedHashSet<Integer>();
// should not be flagged since it is assigned to another variable
List<Integer> l4 = new ArrayList<Integer>();
this.l1 = l4;
// should not be flagged since its contents are accessed
List<Integer> l5 = new ArrayList<Integer>();
if(!l5.contains(23))
l5.add(23);
// should not be flagged since its contents are accessed
List<Integer> l6 = new ArrayList<Integer>();
if(!l6.add(23))
return null;
return s1;
}
public void n(Collection<Set<Integer>> ss) {
// should not be flagged since it is implicitly assigned an existing collection
for (Set<Integer> s : ss)
s.add(23);
}
// should be flagged
private List<Integer> useless = new ArrayList<Integer>();
{
useless.add(23);
useless.remove(0);
}
// should not be flagged since it is annotated with @SuppressWarnings("unused")
@SuppressWarnings("unused")
private List<Integer> l7 = new ArrayList<Integer>();
// should not be flagged since it is annotated with a non-standard annotation suggesting reflective access
@interface MyReflectionAnnotation {}
@MyReflectionAnnotation
private List<Integer> l8 = new ArrayList<Integer>();
}