1616class Test {
1717 public static void main (String [] args ) throws Exception {
1818 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
2122 }
2223
2324 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]
2526 }
2627
2728 public static void copyFiles (Path source , Path target , CopyOption option ) throws Exception {
28- Files .copy ( // the call is a source candidate
29+ Files .copy (
2930 source , // positive example (known sink)
3031 target , // positive example (known sink)
3132 option // no candidate (not modeled, but source and target are modeled)
32- );
33+ ); // $ sourceModel=copy(Path,Path,CopyOption[]):ReturnValue
3334 }
3435
3536 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
3940 }
4041
4142 public static InputStream getInputStream (String openPath ) throws Exception {
4243 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
4447 );
4548 }
4649
4750 public static int compareFiles (File f1 , File f2 ) {
48- return f1 .compareTo ( // compareTo call is a known sanitizer
51+ return f1 .compareTo (
4952 f2 // negative sink example (modeled as not a sink)
5053 ); // the call is a negative source candidate (sanitizer)
5154 }
5255
5356 public static void FilesWalkExample (Path p , FileVisitOption o ) throws Exception {
54- Files .walk ( // the call is a source candidate
57+ Files .walk (
5558 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
5760 o // not a candidate (only the first arg corresponding to a varargs array
5861 // is extracted)
59- );
62+ ); // $ sourceModel=walk(Path,FileVisitOption[]):ReturnValue sinkModel=walk(Path,FileVisitOption[]):Argument[1]
6063 }
6164
6265 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)
6467 }
6568}
6669
6770class 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]
6972 return ;
7073 }
7174
@@ -83,16 +86,16 @@ public FutureTask getTask() {
8386
8487class MoreTests {
8588 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
8992
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
9396
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)
97100 }
98101}
0 commit comments