Restore nullability annotations

This is imperfect since arguments to those annotations will be missing, but at least the common case of a plain `@NotNull` or `@Nullable` will be right, and the `@NotNull`s introduced by the Kotlin compiler will be present as expected.
This commit is contained in:
Chris Smowton
2022-11-24 18:05:33 +00:00
parent 8bbb34a498
commit 70ebb41d67
10 changed files with 111 additions and 3 deletions

View File

@@ -0,0 +1,10 @@
import org.jetbrains.annotations.*;
import zpkg.A;
public class AnnotatedMethods {
public @A @NotNull String notNullAnnotated(@A @NotNull String param) { return param; }
public @A @Nullable String nullableAnnotated(@A @Nullable String param) { return param; }
}

View File

@@ -0,0 +1,7 @@
public class JavaUser {
public static void test(KotlinAnnotatedMethods km) {
km.f(null);
}
}

View File

@@ -0,0 +1,7 @@
import zpkg.A
class KotlinAnnotatedMethods {
@A fun f(@A m: AnnotatedMethods): String = m.notNullAnnotated("hello") + m.nullableAnnotated("world")!!
}

View File

@@ -0,0 +1,6 @@
package org.jetbrains.annotations;
public @interface NotNull {
String value() default "";
Class<? extends Exception> exception() default Exception.class;
}

View File

@@ -0,0 +1,5 @@
package org.jetbrains.annotations;
public @interface Nullable {
String value() default "";
}

View File

@@ -0,0 +1,12 @@
| AnnotatedMethods.java:6:29:6:44 | notNullAnnotated | parameter | AnnotatedMethods.java:6:46:6:47 | A |
| AnnotatedMethods.java:6:29:6:44 | notNullAnnotated | parameter | AnnotatedMethods.java:6:49:6:56 | NotNull |
| AnnotatedMethods.java:6:29:6:44 | notNullAnnotated | return value | AnnotatedMethods.java:6:10:6:11 | A |
| AnnotatedMethods.java:6:29:6:44 | notNullAnnotated | return value | AnnotatedMethods.java:6:13:6:20 | NotNull |
| AnnotatedMethods.java:8:30:8:46 | nullableAnnotated | parameter | AnnotatedMethods.java:8:48:8:49 | A |
| AnnotatedMethods.java:8:30:8:46 | nullableAnnotated | parameter | AnnotatedMethods.java:8:51:8:59 | Nullable |
| AnnotatedMethods.java:8:30:8:46 | nullableAnnotated | return value | AnnotatedMethods.java:8:10:8:11 | A |
| AnnotatedMethods.java:8:30:8:46 | nullableAnnotated | return value | AnnotatedMethods.java:8:13:8:21 | Nullable |
| ktUser.kt:5:6:5:105 | f | parameter | ktUser.kt:0:0:0:0 | NotNull |
| ktUser.kt:5:6:5:105 | f | parameter | ktUser.kt:5:12:5:13 | A |
| ktUser.kt:5:6:5:105 | f | return value | ktUser.kt:0:0:0:0 | NotNull |
| ktUser.kt:5:6:5:105 | f | return value | ktUser.kt:5:3:5:4 | A |

View File

@@ -0,0 +1,6 @@
from create_database_utils import *
os.mkdir('out')
os.mkdir('out2')
os.mkdir('out3')
run_codeql_database_create(["javac AnnotatedMethods.java zpkg/A.java org/jetbrains/annotations/NotNull.java org/jetbrains/annotations/Nullable.java -d out", "kotlinc ktUser.kt -cp out -d out2", "javac JavaUser.java -cp out:out2 -d out3"], lang="java")

View File

@@ -0,0 +1,11 @@
import java
from Method m, string origin, Annotation a
where
m.fromSource() and
(
origin = "return value" and a = m.getAnAnnotation()
or
origin = "parameter" and a = m.getAParameter().getAnAnnotation()
)
select m, origin, a

View File

@@ -0,0 +1,3 @@
package zpkg;
public @interface A { }