Skip to content

Commit

Permalink
[annot] Add test for Kotlin annotations in Java
Browse files Browse the repository at this point in the history
Summary: Add some tests where annotations are defined in Kotlin, but are used on Java methods.

Reviewed By: rgrig

Differential Revision: D64181976

fbshipit-source-id: 472bfa9aa8b4f69766d6ee742d1727cfe07a8af6
  • Loading branch information
hajduakos authored and facebook-github-bot committed Oct 10, 2024
1 parent 63dd699 commit cb7ff1e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ annotation class UserDefinedSink
@Retention(AnnotationRetention.RUNTIME)
annotation class UserDefinedSanitizer

// Testing when Kotlin and Java annotations are used in Kotlin code
class CustomAnnotations {
@UserDefinedSink fun sink(): Unit {}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package codetoanalyze.kotlin.annotreach;

// Testing when Kotlin annotations are used in Java code
class CustomAnnotationsJava {
@UserDefinedSink
void sink() {}

@UserDefinedSanitizer
void canCallSink() {
}

@UserDefinedSource
void source1Bad() {
sink();
}

@UserDefinedSource
void source2Ok() {
canCallSink();
}
}
1 change: 1 addition & 0 deletions infer/tests/codetoanalyze/kotlin/annotreach/issues.exp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
codetoanalyze/kotlin/annotreach/CustomAnnotations.kt, codetoanalyze.kotlin.annotreach.CustomAnnotations.sourceBad():void, 1, CHECKERS_ANNOTATION_REACHABILITY_ERROR, no_bucket, ERROR, [Method sourceBad(), marked as source @UserDefinedSource,calls sink(),sink() defined here, marked as sink @UserDefinedSink]
codetoanalyze/kotlin/annotreach/CustomAnnotations.kt, codetoanalyze.kotlin.annotreach.CustomAnnotations.sourceAndSinkAtTheSameTimeBad():void, 0, CHECKERS_ANNOTATION_REACHABILITY_ERROR, no_bucket, ERROR, []
codetoanalyze/kotlin/annotreach/CustomAnnotations.kt, codetoanalyze.kotlin.annotreach.CustomAnnotations.sourceWithJavaAnnoBad():void, 1, CHECKERS_ANNOTATION_REACHABILITY_ERROR, no_bucket, ERROR, [Method sourceWithJavaAnnoBad(), marked as source @JavaSource,calls sink(),sink() defined here, marked as sink @UserDefinedSink]
codetoanalyze/kotlin/annotreach/CustomAnnotationsJava.java, codetoanalyze.kotlin.annotreach.CustomAnnotationsJava.source1Bad():void, 1, CHECKERS_ANNOTATION_REACHABILITY_ERROR, no_bucket, ERROR, [Method source1Bad(), marked as source @UserDefinedSource,calls sink(),sink() defined here, marked as sink @UserDefinedSink]

0 comments on commit cb7ff1e

Please sign in to comment.