1- import java .math .BigDecimal ;
1+ import java .sql .PreparedStatement ;
2+ import java .sql .DriverManager ;
3+ import java .sql .Connection ;
24import java .sql .ResultSet ;
5+ import java .math .BigDecimal ;
6+ import java .io .IOException ;
7+ import java .util .concurrent .atomic .AtomicInteger ;
8+ import java .util .concurrent .atomic .AtomicReference ;
9+ import java .util .concurrent .CountDownLatch ;
10+ import java .util .function .Function ;
11+ import java .util .function .Supplier ;
12+ import java .util .StringJoiner ;
313
414public class Test {
515
@@ -9,37 +19,124 @@ void sink(Object o) { }
919
1020 public void test () throws Exception {
1121
12- Exception e1 = new RuntimeException ((String )source ());
13- sink ((String )e1 .getMessage ()); // $hasValueFlow
22+ // top 100 JDK APIs tests
23+ {
24+ Exception e1 = new RuntimeException ((String )source ());
25+ sink ((String )e1 .getMessage ()); // $hasValueFlow
26+
27+ Exception e2 = new RuntimeException ((Throwable )source ());
28+ sink ((Throwable )e2 .getCause ()); // $hasValueFlow
29+
30+ Exception e3 = new IllegalArgumentException ((String )source ());
31+ sink ((String )e3 .getMessage ()); // $hasValueFlow
32+
33+ Exception e4 = new IllegalStateException ((String )source ());
34+ sink ((String )e4 .getMessage ()); // $hasValueFlow
35+
36+ Throwable t = new Throwable ((Throwable )source ());
37+ sink ((Throwable )t .getCause ()); // $hasValueFlow
38+
39+ Integer x = (Integer )source ();
40+ int y = x ;
41+ sink (String .valueOf (y )); // $hasTaintFlow
42+
43+ String s1 = (String )source ();
44+ sink (Integer .parseInt (s1 )); // $hasTaintFlow
45+
46+ String s2 = (String )source ();
47+ int i = 0 ;
48+ sink (s2 .charAt (i )); // $hasTaintFlow
49+
50+ String s3 = (String )source ();
51+ sink (new BigDecimal (s3 )); // $hasTaintFlow
52+
53+ ResultSet rs = (ResultSet )source ();
54+ sink (rs .getString ("" )); // $hasTaintFlow
55+ }
56+
57+ // top 200 JDK APIs tests
58+ {
59+ // java.io
60+ Exception e1 = new IOException ((String )source ());
61+ sink ((String )e1 .getMessage ()); // $hasValueFlow
62+
63+ // java.lang
64+ Exception e2 = new Exception ((String )source ());
65+ sink ((String )e2 .getMessage ()); // $hasValueFlow
66+
67+ Exception e3 = new IndexOutOfBoundsException ((String )source ());
68+ sink ((String )e3 .getMessage ()); // $hasValueFlow
69+
70+ Exception e4 = new RuntimeException ((String )source (), (Throwable )source ());
71+ sink ((String )e4 .getMessage ()); // $hasValueFlow
72+ sink ((Throwable )e4 .getCause ()); // $hasValueFlow
73+
74+ Integer i1 = (Integer )source ();
75+ sink (i1 .intValue ()); // $hasTaintFlow
76+
77+ int i2 = (int )source ();
78+ sink (Integer .toString (i2 )); // $hasTaintFlow
79+
80+ int i3 = (int )source ();
81+ sink (Integer .valueOf (i3 )); // $hasTaintFlow
82+
83+ Long l1 = (Long )source ();
84+ sink (l1 .longValue ()); // $hasTaintFlow
85+
86+ String s1 = (String )source ();
87+ sink (Long .parseLong (s1 )); // $hasTaintFlow
88+
89+ Long l2 = (Long )source ();
90+ sink (l2 .toString ()); // $hasTaintFlow
91+
92+ long l3 = (long )source ();
93+ sink (String .valueOf (l3 )); // $hasTaintFlow
94+
95+ // System sys = (System)source();
96+ // sink(sys.getProperty("")); // $hasValueFlow
97+
98+ // java.math
99+ long l4 = (long )source ();
100+ sink (BigDecimal .valueOf (l4 )); // $hasTaintFlow
101+
102+ double d1 = (double )source ();
103+ sink (BigDecimal .valueOf (d1 )); // $hasTaintFlow
14104
15- Exception e2 = new RuntimeException ((Throwable )source ());
16- sink ((Throwable )e2 .getCause ()); // $hasValueFlow
105+ int i4 = (int )source ();
106+ int i5 = (int )source ();
107+ sink (Math .min (i4 , i5 )); // $hasValueFlow
17108
18- Exception e3 = new IllegalArgumentException ((String )source ());
19- sink ((String )e3 .getMessage ()); // $hasValueFlow
109+ // java.sql
110+ // Connection con = DriverManager.getConnection("");
111+ // PreparedStatement ps = con.prepareStatement("UPDATE EMPLOYEES SET NAME = ? WHERE ID = ?");
112+ // ps.setString(1, "testName"); // $hasValueFlow
113+ // ps.setInt(2, 110592); // $hasValueFlow
20114
21- Exception e4 = new IllegalStateException (( String )source () );
22- sink (( String ) e4 . getMessage ( )); // $hasValueFlow
115+ ResultSet rs = ( ResultSet )source ();
116+ sink (rs . getInt ( "" )); // $hasTaintFlow
23117
24- Throwable t = new Throwable ((Throwable )source ());
25- sink ((Throwable )t .getCause ()); // $hasValueFlow
118+ // java.util.concurrent.atomic
119+ // AtomicInteger ai = new AtomicInteger((int)source());
120+ // sink((int)ai.get()); // $hasValueFlow
26121
27- Integer x = (Integer )source ();
28- int y = x ;
29- sink (String .valueOf (y )); // $hasTaintFlow
122+ // AtomicReference ar = new AtomicReference(source());
123+ // sink(ar.get()); // $hasValueFlow
30124
31- String s1 = (String )source ();
32- sink (Integer .parseInt (s1 )); // $hasTaintFlow
125+ // java.util.concurrent
126+ CountDownLatch cdl = new CountDownLatch ((int )source ());
127+ sink (cdl .getCount ()); // $hasValueFlow
33128
34- String s2 = ( String ) source ();
35- int i = 0 ;
36- sink (s2 . charAt ( i )); // $hasTaintFlow
129+ // java.util.function
130+ // Function<Object, Object> func = a -> a + "" ;
131+ // sink(func.apply(source())); // $hasTaintFlow
37132
38- String s3 = (String )source ();
39- sink (new BigDecimal ( s3 )); // $hasTaintFlow
133+ Supplier < Double > sup = (Supplier )source ();
134+ sink (sup . get ( )); // $hasValueFlow
40135
41- ResultSet rs = (ResultSet )source ();
42- sink (rs .getString ("" )); // $hasTaintFlow
136+ // java.util
137+ // StringJoiner sj = new StringJoiner(",");
138+ // sink(sj.add((CharSequence)source())); // $hasTaintFlow
139+ }
43140
44141 }
45142}
0 commit comments