16
16
class Test {
17
17
public static void main (String [] args ) throws Exception {
18
18
AtomicReference <String > reference = new AtomicReference <>(); // uninteresting (parameterless constructor)
19
- reference .set (args [0 ]); // arg[0] is not a candidate (modeled as value flow step)
20
- // ^^^^^^ Argument[this] is a candidate
19
+ reference .set ( // $ sinkModel=set(Object):Argument[this]
20
+ args [0 ] // not a sink candidate (modeled as a flow step)
21
+ ); // $ sourceModel=set(Object):ReturnValue
21
22
}
22
23
23
24
public static void callSupplier (Supplier <String > supplier ) {
24
- supplier .get (); // Argument[this] is a sink candidate; the call is a source candidate
25
+ supplier .get (); // $ sourceModel=get():ReturnValue sinkModel=get(): Argument[this]
25
26
}
26
27
27
28
public static void copyFiles (Path source , Path target , CopyOption option ) throws Exception {
28
- Files .copy ( // the call is a source candidate
29
+ Files .copy (
29
30
source , // positive example (known sink)
30
31
target , // positive example (known sink)
31
32
option // no candidate (not modeled, but source and target are modeled)
32
- );
33
+ ); // $ sourceModel=copy(Path,Path,CopyOption[]):ReturnValue
33
34
}
34
35
35
36
public static InputStream getInputStream (Path openPath ) throws Exception {
36
- return Files .newInputStream ( // the call is a source candidate
37
- openPath // positive example (known sink), candidate ("only" ai-modeled, and useful as a candidate in regression testing)
38
- );
37
+ return Files .newInputStream (
38
+ openPath // $ sinkModel=newInputStream(Path,OpenOption[]):Argument[0] // positive example (known sink), candidate ("only" ai-modeled, and useful as a candidate in regression testing)
39
+ ); // $ sourceModel=newInputStream(Path,OpenOption[]):ReturnValue
39
40
}
40
41
41
42
public static InputStream getInputStream (String openPath ) throws Exception {
42
43
return Test .getInputStream ( // the call is not a source candidate (argument to local call)
43
- Paths .get (openPath ) // no sink candidate (argument to local call); the call is a source candidate
44
+ Paths .get (
45
+ openPath // not a sink candidate (argument to local call)
46
+ ) // $ sourceModel=get(String,String[]):ReturnValue
44
47
);
45
48
}
46
49
47
50
public static int compareFiles (File f1 , File f2 ) {
48
- return f1 .compareTo ( // compareTo call is a known sanitizer
51
+ return f1 .compareTo (
49
52
f2 // negative sink example (modeled as not a sink)
50
53
); // the call is a negative source candidate (sanitizer)
51
54
}
52
55
53
56
public static void FilesWalkExample (Path p , FileVisitOption o ) throws Exception {
54
- Files .walk ( // the call is a source candidate
57
+ Files .walk (
55
58
p , // negative sink example (modeled as a taint step)
56
- o , // the implicit varargs array is a candidate
59
+ o , // the implicit varargs array is a candidate, annotated on the last line of the call
57
60
o // not a candidate (only the first arg corresponding to a varargs array
58
61
// is extracted)
59
- );
62
+ ); // $ sourceModel=walk(Path,FileVisitOption[]):ReturnValue sinkModel=walk(Path,FileVisitOption[]):Argument[1]
60
63
}
61
64
62
65
public static void WebSocketExample (URLConnection c ) throws Exception {
63
- c .getInputStream (); // the call is a source example, c is a sink candidate
66
+ c .getInputStream (); // $ sinkModel=getInputStream():Argument[this] // not a source candidate (manual modeling)
64
67
}
65
68
}
66
69
67
70
class OverrideTest extends Exception {
68
- public void printStackTrace (PrintWriter writer ) { // writer is a source candidate because it overrides an existing method
71
+ public void printStackTrace (PrintWriter writer ) { // $ sourceModel=printStackTrace(PrintWriter):Parameter[0]
69
72
return ;
70
73
}
71
74
@@ -83,16 +86,16 @@ public FutureTask getTask() {
83
86
84
87
class MoreTests {
85
88
public static void FilesListExample (Path p ) throws Exception {
86
- Files .list ( // the call is a source candidate
87
- Files .createDirectories (p ) // the call is a source candidate, but not a sink candidate (modeled as a taint step)
88
- );
89
+ Files .list (
90
+ Files .createDirectories (p ) // $ sourceModel=createDirectories(Path,FileAttribute[]):ReturnValue // not a sink candidate (modeled as a taint step)
91
+ ); // $ sourceModel=list(Path):ReturnValue
89
92
90
- Files .delete ( // not a source candidate (return type is void)
91
- p // sink candidate
92
- );
93
+ Files .delete (
94
+ p // $ sinkModel=delete(Path):Argument[0]
95
+ ); // $ SPURIOUS: sourceModel=delete(Path):ReturnValue
93
96
94
- Files .deleteIfExists ( // not a source candidate (return type is boolean)
95
- p // sink candidate
96
- );
97
+ Files .deleteIfExists (
98
+ p // $ sinkModel=deleteIfExists(Path):Argument[0]
99
+ ); // not a source candidate (return type is boolean)
97
100
}
98
101
}
0 commit comments