Skip to content

Commit

Permalink
[annot] Add test for breaking cycles in call graph
Browse files Browse the repository at this point in the history
Summary: Add two examples with the exact same topology of the callgraph, just different function names. Infer finds source to sink path in one, but not in the other.

Reviewed By: jvillard

Differential Revision: D68266171

fbshipit-source-id: 1725cfef52f8dd7594460360a58a212e94c1ee33
  • Loading branch information
hajduakos authored and facebook-github-bot committed Jan 16, 2025
1 parent ca4f3ff commit bbade7f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
41 changes: 41 additions & 0 deletions infer/tests/codetoanalyze/java/annotreach/CustomAnnotations.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,44 @@ public void sink() {}
@UserDefinedSource1
class DerivedWithSourceConstructor extends BaseConstructorCallsSink {}
}

// Testing that Infer can break a cycle
class Recursion {
// Breaks it in the "wrong" way, misses trace
@UserDefinedSource1
void sourceBad_FN() {
g();
}

void g() {
f();
}

void f() {
g();
sink();
}

@UserDefinedSink1
void sink() {}
}

// Same example as above, just "f" and "g" swapped, Infer finds the trace
class RecursionSlightlyRenamed {
@UserDefinedSource1
void sourceBad() {
f();
}

void f() {
g();
}

void g() {
f();
sink();
}

@UserDefinedSink1
void sink() {}
}
2 changes: 1 addition & 1 deletion infer/tests/codetoanalyze/java/annotreach/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

TESTS_DIR = ../../..

INFER_OPTIONS = --debug-exceptions --annotation-reachability-only
INFER_OPTIONS = --debug-exceptions --annotation-reachability-only --scheduler restart

INFERPRINT_OPTIONS = --issues-tests
SOURCES = $(wildcard *.java)
Expand Down
1 change: 1 addition & 0 deletions infer/tests/codetoanalyze/java/annotreach/issues.exp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ codetoanalyze/java/annotreach/CustomAnnotations.java, codetoanalyze.java.checker
codetoanalyze/java/annotreach/CustomAnnotations.java, codetoanalyze.java.checkers.CustomAnnotations.callsDeprecatedMethodBad():void, 1, CHECKERS_ANNOTATION_REACHABILITY_ERROR, no_bucket, ERROR, [Method callsDeprecatedMethodBad(), marked as source @AnySource,calls deprecatedMethod(),deprecatedMethod() defined here, marked as sink @Deprecated]
codetoanalyze/java/annotreach/CustomAnnotations.java, codetoanalyze.java.checkers.CustomAnnotations$GenericDerived.source(java.lang.Object):void, 8, CHECKERS_ANNOTATION_REACHABILITY_ERROR, no_bucket, ERROR, [Method source(...), marked as source @UserDefinedSource1,calls source(...),source(...) defined here,calls sink(),sink() defined here, marked as sink @UserDefinedSink1]
codetoanalyze/java/annotreach/CustomAnnotations.java, codetoanalyze.java.checkers.CustomAnnotations$DerivedWithSourceConstructor.<init>(codetoanalyze.java.checkers.CustomAnnotations), 0, CHECKERS_ANNOTATION_REACHABILITY_ERROR, no_bucket, ERROR, [Constructor CustomAnnotations$DerivedWithSourceConstructor(...), marked as source @UserDefinedSource1,calls CustomAnnotations$BaseConstructorCallsSink(...),CustomAnnotations$BaseConstructorCallsSink(...) defined here,calls sink(),sink() defined here, marked as sink @UserDefinedSink1]
codetoanalyze/java/annotreach/CustomAnnotations.java, codetoanalyze.java.checkers.RecursionSlightlyRenamed.sourceBad():void, 1, CHECKERS_ANNOTATION_REACHABILITY_ERROR, no_bucket, ERROR, [Method sourceBad(), marked as source @UserDefinedSource1,calls f(),f() defined here,calls g(),g() defined here,calls sink(),sink() defined here, marked as sink @UserDefinedSink1]
codetoanalyze/java/annotreach/ExpensiveCallExample.java, codetoanalyze.java.checkers.PerformanceCriticalClass.performanceCriticalMethod1(codetoanalyze.java.checkers.ExpensiveClass):void, 1, CHECKERS_CALLS_EXPENSIVE_METHOD, no_bucket, ERROR, [Method performanceCriticalMethod1(...), marked as source @PerformanceCritical,calls anExpensiveMethod(),anExpensiveMethod() defined here, marked as sink @Expensive]
codetoanalyze/java/annotreach/ExpensiveCallExample.java, codetoanalyze.java.checkers.PerformanceCriticalClass.performanceCriticalMethod2(codetoanalyze.java.checkers.Other):void, 1, CHECKERS_CALLS_EXPENSIVE_METHOD, no_bucket, ERROR, [Method performanceCriticalMethod2(...), marked as source @PerformanceCritical,calls expensive(),expensive() defined here, marked as sink @Expensive]
codetoanalyze/java/annotreach/ExpensiveCallExample.java, codetoanalyze.java.checkers.PerformanceCriticalClass.performanceCriticalMethod3(codetoanalyze.java.checkers.Other):void, 1, CHECKERS_CALLS_EXPENSIVE_METHOD, no_bucket, ERROR, [Method performanceCriticalMethod3(...), marked as source @PerformanceCritical,calls callsExpensive1(),callsExpensive1() defined here,calls expensive(),expensive() defined here, marked as sink @Expensive]
Expand Down

0 comments on commit bbade7f

Please sign in to comment.