1 package gcUnrelatedTypes;
2
3 import java.util.ArrayList;
4
5 import edu.umd.cs.findbugs.annotations.ExpectWarning;
6
7 public class ArrayListContains<T> {
8
9 static class Dummy {
10
11 }
12
13 static class DummyChild extends Dummy {
14
15 }
16
17 private ArrayList<?> wildcardF;
18
19 private ArrayList<Dummy> dummyF;
20 private ArrayList<? extends Dummy> dummyEF;
21 private ArrayList<? super Dummy> dummySF;
22
23 private ArrayList<DummyChild> childF;
24 private ArrayList<? extends DummyChild> childEF;
25 private ArrayList<? super DummyChild> childSF;
26
27 private ArrayList<T> genericF;
28 private ArrayList<? extends T> genericEF;
29 private ArrayList<? super T> genericSF;
30
31 @ExpectWarning("GC")
32 public ArrayListContains(
33 ArrayList<?> wildcardF,
34 ArrayList<Dummy> dummyF,
35 ArrayList<? extends Dummy> dummyEF,
36 ArrayList<? super Dummy> dummySF,
37 ArrayList<DummyChild> childF,
38 ArrayList<? extends DummyChild> childEF,
39 ArrayList<? super DummyChild> childSF,
40 ArrayList<T> genericF,
41 ArrayList<? extends T> genericEF,
42 ArrayList<? super T> genericSF) {
43 this.wildcardF = wildcardF;
44 this.dummyF = dummyF;
45 this.dummyEF = dummyEF;
46 this.dummySF = dummySF;
47 this.childF = childF;
48 this.childEF = childEF;
49 this.childSF = childSF;
50 this.genericF = genericF;
51 this.genericEF = genericEF;
52 this.genericSF = genericSF;
53
54 Dummy dummy = new Dummy();
55 DummyChild dummyChild = new DummyChild();
56 String s = "Mismatched Type";
57
58 wildcardF.contains(dummy);
59 wildcardF.contains(dummyChild);
60 wildcardF.contains(s);
61
62 dummyF.contains(dummy);
63 dummyF.contains(dummyChild);
64 dummyF.contains(s);
65
66 dummyEF.contains(dummy);
67 dummyEF.contains(dummyChild);
68 dummyEF.contains(s);
69
70 dummySF.contains(dummy);
71 dummySF.contains(dummyChild);
72 dummySF.contains(s);
73
74 childF.contains(dummy);
75 childF.contains(dummyChild);
76 childF.contains(s);
77
78 childEF.contains(dummy);
79 childEF.contains(dummyChild);
80 childEF.contains(s);
81
82 childSF.contains(dummy);
83 childSF.contains(dummyChild);
84 childSF.contains(s);
85
86 genericF.contains(dummy);
87 genericF.contains(dummyChild);
88 genericF.contains(s);
89
90 genericEF.contains(dummy);
91 genericEF.contains(dummyChild);
92 genericEF.contains(s);
93
94 genericSF.contains(dummy);
95 genericSF.contains(dummyChild);
96 genericSF.contains(s);
97
98 }
99
100 @ExpectWarning("GC")
101 public void testFields() {
102 Dummy dummy = new Dummy();
103 DummyChild dummyChild = new DummyChild();
104 String s = "Mismatched Type";
105
106 wildcardF.contains(dummy);
107 wildcardF.contains(dummyChild);
108 wildcardF.contains(s);
109
110 dummyF.contains(dummy);
111 dummyF.contains(dummyChild);
112 dummyF.contains(s);
113
114 dummyEF.contains(dummy);
115 dummyEF.contains(dummyChild);
116 dummyEF.contains(s);
117
118 dummySF.contains(dummy);
119 dummySF.contains(dummyChild);
120 dummySF.contains(s);
121
122 childF.contains(dummy);
123 childF.contains(dummyChild);
124 childF.contains(s);
125
126 childEF.contains(dummy);
127 childEF.contains(dummyChild);
128 childEF.contains(s);
129
130 childSF.contains(dummy);
131 childSF.contains(dummyChild);
132 childSF.contains(s);
133
134 genericF.contains(dummy);
135 genericF.contains(dummyChild);
136 genericF.contains(s);
137
138 genericEF.contains(dummy);
139 genericEF.contains(dummyChild);
140 genericEF.contains(s);
141
142 genericSF.contains(dummy);
143 genericSF.contains(dummyChild);
144 genericSF.contains(s);
145
146
147
148
149
150 }
151 }