-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathTest.java
198 lines (149 loc) · 7.07 KB
/
Test.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package generatedtest; // for java.util.ResourceBundle.getString test
import java.awt.*;
import java.io.*;
import java.math.BigDecimal;
import java.net.URL;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.EventObject;
import java.util.ResourceBundle;
import java.util.StringJoiner;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
public class Test {
void sink(Object o) { }
Object source() { return null; }
Object newWithMapValueDefault(Object element) { return null; } // for java.util.ResourceBundle.getString test
public void test() throws Exception {
// top 100 JDK APIs tests
{
Exception e1 = new RuntimeException((String)source());
sink((String)e1.getMessage()); // $hasValueFlow
Exception e2 = new RuntimeException((Throwable)source());
sink((Throwable)e2.getCause()); // $hasValueFlow
Exception e3 = new IllegalArgumentException((String)source());
sink((String)e3.getMessage()); // $hasValueFlow
Exception e4 = new IllegalStateException((String)source());
sink((String)e4.getMessage()); // $hasValueFlow
Exception e5 = new UnsupportedOperationException((String)source());
sink((String)e5.getMessage()); // $hasValueFlow
Throwable t = new Throwable((Throwable)source());
sink((Throwable)t.getCause()); // $hasValueFlow
String s2 = (String)source();
int i = 0;
sink(s2.charAt(i)); // $hasTaintFlow
ResultSet rs = (ResultSet)source();
sink(rs.getString("")); // $hasTaintFlow
}
// top 200 JDK APIs tests
{
// java.io
Exception e1 = new IOException((String)source());
sink((String)e1.getMessage()); // $hasValueFlow
File f = (File)source();
sink(f.getName()); // $hasTaintFlow
// java.lang
Exception e2 = new Exception((String)source());
sink((String)e2.getMessage()); // $hasValueFlow
Exception e3 = new IndexOutOfBoundsException((String)source());
sink((String)e3.getMessage()); // $hasValueFlow
Exception e4 = new RuntimeException((String)source(), (Throwable)source());
sink((String)e4.getMessage()); // $hasValueFlow
sink((Throwable)e4.getCause()); // $hasValueFlow
// java.sql
Connection con = DriverManager.getConnection("");
PreparedStatement ps1 = con.prepareStatement("UPDATE EMPLOYEES SET NAME = ? WHERE ID = ?");
ps1.setString(1, (String)source());
sink(ps1); // safe
// java.util.concurrent.atomic
AtomicReference ar = new AtomicReference(source());
sink(ar.get()); // $hasValueFlow
// java.util
StringJoiner sj1 = new StringJoiner(",");
sink(sj1.add((CharSequence)source())); // $hasTaintFlow
StringJoiner sj2 = (StringJoiner)source();
sink(sj2.add("test")); // $hasValueFlow
}
// top 300-500 JDK APIs tests
{
// java.awt
Container container = new Container();
sink(container.add((Component)source())); // $hasValueFlow
// java.io
File f1 = (File)source();
sink(f1.getParentFile()); // $hasTaintFlow
File f2 = (File)source();
sink(f2.getPath()); // $hasTaintFlow
StringWriter sw = (StringWriter)source();
sink(sw.toString()); // $hasTaintFlow
Exception e = new UncheckedIOException((IOException)source());
sink((Throwable)e.getCause()); // $hasValueFlow
// java.net
URL url = (URL)source();
sink(url.toURI()); // $hasTaintFlow
// java.nio.file
Path p = (Path)source();
sink(p.getFileName()); // $hasTaintFlow
// java.util.concurrent.atomic
AtomicReference ar = new AtomicReference();
ar.set(source());
sink(ar.get()); // $hasValueFlow
// java.util.concurrent
// `ThreadPoolExecutor` implements the `java.util.concurrent.ExecutorService` interface
ThreadPoolExecutor tpe = new ThreadPoolExecutor(0, 0, 0, null, null);
sink(tpe.submit((Runnable)source())); // $hasTaintFlow
CompletionStage cs = (CompletionStage)source();
sink(cs.toCompletableFuture()); // $hasTaintFlow
CompletableFuture cf1 = new CompletableFuture();
cf1.complete(source());
sink(cf1.get()); // $hasValueFlow
sink(cf1.join()); // $hasValueFlow
CompletableFuture cf2 = CompletableFuture.completedFuture(source());
sink(cf2.get()); // $hasValueFlow
sink(cf2.join()); // $hasValueFlow
// java.util.logging
Logger logger = Logger.getLogger((String)source());
sink(logger.getName()); // $hasValueFlow
// java.util.regex
Pattern pattern = Pattern.compile((String)source());
sink(pattern); // $hasTaintFlow
// java.util
EventObject eventObj = new EventObject(source());
sink(eventObj.getSource()); // $hasValueFlow
// "java.util;ResourceBundle;true;getString;(String);;Argument[-1].MapValue;ReturnValue;value;manual"
String out = null;
ResourceBundle in = (ResourceBundle)newWithMapValueDefault(source());
out = in.getString(null);
sink(out); // $ hasValueFlow
// java.lang
AssertionError assertErr = new AssertionError(source());
sink((String)assertErr.getMessage()); // $hasValueFlow
sink(Test.class.cast(source())); // $hasValueFlow
Exception excep1 = new Exception((String)source(), (Throwable)source());
sink((String)excep1.getMessage()); // $hasValueFlow
sink((Throwable)excep1.getCause()); // $hasValueFlow
Exception excep2 = new NullPointerException((String)source());
sink((String)excep2.getMessage()); // $hasValueFlow
StringBuilder sb = (StringBuilder)source();
sink(sb.delete(0, 1)); // $hasValueFlow
Thread thread1 = new Thread((Runnable)source());
sink(thread1); // $hasTaintFlow
Thread thread2 = new Thread((String)source());
sink(thread2.getName()); // $hasValueFlow
ThreadLocal threadloc = new ThreadLocal();
threadloc.set(source());
sink(threadloc.get()); // $hasValueFlow
Throwable th = new Throwable((String)source());
sink((String)th.getLocalizedMessage()); // $hasValueFlow
sink(th.toString()); // $hasTaintFlow
}
}
}