Generate foreign annotation test data for FIR
This commit is contained in:
+52
@@ -0,0 +1,52 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
|
||||
// FILE: A.java
|
||||
import androidx.annotation.*;
|
||||
|
||||
public class A<T> {
|
||||
@RecentlyNullable public String field = null;
|
||||
|
||||
@RecentlyNullable
|
||||
public String foo(@RecentlyNonNull String x, @RecentlyNullable CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@RecentlyNonNull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@RecentlyNullable
|
||||
public T baz(@RecentlyNonNull T x) { return x; }
|
||||
|
||||
@RecentlyNonNull
|
||||
public T baz2(@RecentlyNullable T x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A<String>, a1: A<String?>) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.baz("")<!UNSAFE_CALL!>.<!>length
|
||||
a.baz("")?.length
|
||||
a.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a1.baz("")!!.length
|
||||
a1.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)!!.length
|
||||
|
||||
a.baz2("").length
|
||||
a.baz2("")<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
a.baz2("")<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.baz2(null).length
|
||||
a.baz2(null)<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
a.baz2(null)<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
|
||||
// FILE: A.java
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
|
||||
// FILE: A.java
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
|
||||
// FILE: A.java
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// SOURCE_RETENTION_ANNOTATIONS
|
||||
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
|
||||
// FILE: A.java
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
|
||||
// FILE: A.java
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
|
||||
// FILE: A.java
|
||||
|
||||
Vendored
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
|
||||
// FILE: UnknownQualifier.java
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +TypeEnhancementImprovementsInStrictMode
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: strict
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: ignore
|
||||
|
||||
// FILE: A.java
|
||||
import javax.annotation.*;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public class A {
|
||||
@Nullable public String field = null;
|
||||
|
||||
public String foo(String q, @Nonnull String x, @CheckForNull CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A) {
|
||||
// foo is platform
|
||||
a.foo("", "", null)?.length
|
||||
a.foo("", "", null).length
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, <!NULL_FOR_NONNULL_TYPE!>null<!>, "").length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: strict
|
||||
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: strict
|
||||
|
||||
|
||||
Vendored
+85
@@ -0,0 +1,85 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: MyNotNull.java
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierNickname;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.METHOD, ElementType.PARAMETER})
|
||||
@Nonnull
|
||||
@TypeQualifierNickname
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MyNotNull {}
|
||||
|
||||
|
||||
// FILE: AnnotatedWithJsr.java
|
||||
public class AnnotatedWithJsr {
|
||||
@MyNotNull
|
||||
public String getString() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void consumeString(@MyNotNull String s) { }
|
||||
}
|
||||
|
||||
|
||||
|
||||
// FILE: AnnotatedWithJB.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AnnotatedWithJB {
|
||||
public @NotNull String getString() {
|
||||
return "hello";
|
||||
}
|
||||
|
||||
public void consumeString(@NotNull String s) { }
|
||||
}
|
||||
|
||||
|
||||
// FILE: PlainJava.java
|
||||
public class PlainJava {
|
||||
public String getString() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void consumeString(String s) { }
|
||||
}
|
||||
|
||||
|
||||
// FILE: main.kt
|
||||
val jsr: AnnotatedWithJsr = AnnotatedWithJsr()
|
||||
val jsrNullable: AnnotatedWithJsr? = null
|
||||
|
||||
val jb: AnnotatedWithJB = AnnotatedWithJB()
|
||||
val jbNullable: AnnotatedWithJB? = null
|
||||
|
||||
val platform: PlainJava = PlainJava()
|
||||
val platformNullable: PlainJava? = null
|
||||
|
||||
object Elvis {
|
||||
fun fromJava() {
|
||||
val a = jsr.string <!USELESS_ELVIS!>?: ""<!>
|
||||
val b = jsrNullable?.string ?: ""
|
||||
|
||||
val c = jb.string <!USELESS_ELVIS!>?: ""<!>
|
||||
val d = jbNullable?.string ?: ""
|
||||
|
||||
val e = platform.string ?: ""
|
||||
val f = platformNullable?.string ?: ""
|
||||
}
|
||||
|
||||
fun toJava(nullableString: String?) {
|
||||
val b = jsr.consumeString(nullableString ?: "")
|
||||
val d = jsrNullable?.consumeString(nullableString ?: "")
|
||||
|
||||
val f = jb.consumeString(nullableString ?: "")
|
||||
val h = jbNullable?.consumeString(nullableString ?: "")
|
||||
|
||||
val j = platform.consumeString(nullableString ?: "")
|
||||
val l = platformNullable?.consumeString(nullableString ?: "")
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
@MyNonnull
|
||||
public static Integer staticNN;
|
||||
@MyNullable
|
||||
public static Integer staticN;
|
||||
public static Integer staticJ;
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
fun test() {
|
||||
var platformNN = J.staticNN
|
||||
var platformN = J.staticN
|
||||
var platformJ = J.staticJ
|
||||
|
||||
+platformNN
|
||||
<!UNSAFE_CALL!>+<!>platformN
|
||||
+platformJ
|
||||
|
||||
++platformNN
|
||||
<!UNSAFE_CALL!>++<!>platformN
|
||||
++platformJ
|
||||
|
||||
platformNN++
|
||||
platformN++
|
||||
platformJ++
|
||||
|
||||
1 + platformNN
|
||||
1 + platformN
|
||||
1 + platformJ
|
||||
|
||||
platformNN + 1
|
||||
platformN + 1
|
||||
platformJ + 1
|
||||
|
||||
1 <!INFIX_MODIFIER_REQUIRED!>plus<!> platformNN
|
||||
1 <!INFIX_MODIFIER_REQUIRED!>plus<!> platformN
|
||||
1 <!INFIX_MODIFIER_REQUIRED!>plus<!> platformJ
|
||||
|
||||
platformNN <!INFIX_MODIFIER_REQUIRED!>plus<!> 1
|
||||
platformN <!INFIX_MODIFIER_REQUIRED!>plus<!> 1
|
||||
platformJ <!INFIX_MODIFIER_REQUIRED!>plus<!> 1
|
||||
|
||||
platformNN += 1
|
||||
platformN += 1
|
||||
platformJ += 1
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
@MyNonnull
|
||||
public static Integer[] staticNN;
|
||||
@MyNullable
|
||||
public static Integer[] staticN;
|
||||
public static Integer[] staticJ;
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
fun test() {
|
||||
val platformNN = J.staticNN
|
||||
val platformN = J.staticN
|
||||
val platformJ = J.staticJ
|
||||
|
||||
platformNN[0]
|
||||
<!UNSAFE_CALL!>platformN[0]<!>
|
||||
platformJ[0]
|
||||
|
||||
platformNN[0] = 1
|
||||
<!UNSAFE_CALL!>platformN[0]<!> = 1
|
||||
platformJ[0] = 1
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
@MyNonnull
|
||||
public static J staticNN;
|
||||
@MyNullable
|
||||
public static J staticN;
|
||||
public static J staticJ;
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
var v: J = J()
|
||||
var n: J? = J()
|
||||
|
||||
fun test() {
|
||||
v = J.staticNN
|
||||
v = <!ASSIGNMENT_TYPE_MISMATCH!>J.staticN<!>
|
||||
v = J.staticJ
|
||||
|
||||
n = J.staticNN
|
||||
n = J.staticN
|
||||
n = J.staticJ
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
@MyNonnull
|
||||
public static Boolean staticNN;
|
||||
@MyNullable
|
||||
public static Boolean staticN;
|
||||
public static Boolean staticJ;
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
fun test() {
|
||||
val platformNN = J.staticNN
|
||||
val platformN = J.staticN
|
||||
val platformJ = J.staticJ
|
||||
|
||||
if (platformNN) {}
|
||||
if (<!CONDITION_TYPE_MISMATCH!>platformN<!>) {}
|
||||
if (platformJ) {}
|
||||
|
||||
while (platformNN) {}
|
||||
while (<!CONDITION_TYPE_MISMATCH!>platformN<!>) {}
|
||||
while (platformJ) {}
|
||||
|
||||
do {} while (platformNN)
|
||||
do {} while (<!CONDITION_TYPE_MISMATCH!>platformN<!>)
|
||||
do {} while (platformJ)
|
||||
|
||||
platformNN && false
|
||||
<!CONDITION_TYPE_MISMATCH!>platformN<!> && false
|
||||
platformJ && false
|
||||
|
||||
platformNN || false
|
||||
<!CONDITION_TYPE_MISMATCH!>platformN<!> || false
|
||||
platformJ || false
|
||||
|
||||
!platformNN
|
||||
<!UNSAFE_CALL!>!<!>platformN
|
||||
!platformJ
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
@MyNonnull
|
||||
public static J staticNN;
|
||||
@MyNullable
|
||||
public static J staticN;
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
fun test() {
|
||||
val n = J.staticN
|
||||
foo(<!ARGUMENT_TYPE_MISMATCH!>n<!>)
|
||||
J.staticNN = <!ASSIGNMENT_TYPE_MISMATCH!>n<!>
|
||||
if (n != null) {
|
||||
foo(n)
|
||||
J.staticNN = n
|
||||
}
|
||||
|
||||
val x: J? = null
|
||||
J.staticNN = <!ASSIGNMENT_TYPE_MISMATCH!>x<!>
|
||||
if (x != null) {
|
||||
J.staticNN = x
|
||||
}
|
||||
}
|
||||
|
||||
fun foo(j: J) {}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
@MyNonnull
|
||||
public static J staticNN;
|
||||
@MyNullable
|
||||
public static J staticN;
|
||||
public static J staticJ;
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
fun test() {
|
||||
val platformNN = J.staticNN
|
||||
val platformN = J.staticN
|
||||
val platformJ = J.staticJ
|
||||
|
||||
fun foo(p: J = platformNN, p1: J = platformN, p2: J = platformJ) {}
|
||||
|
||||
fun foo1(p: J? = platformNN, p1: J? = platformN, p2: J? = platformJ) {}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
|
||||
public interface DP {
|
||||
String getValue(Object a, Object b);
|
||||
String setValue(Object a, Object b, Object c);
|
||||
}
|
||||
|
||||
@MyNonnull
|
||||
public static DP staticNN;
|
||||
@MyNullable
|
||||
public static DP staticN;
|
||||
public static DP staticJ;
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
var A by J.staticNN
|
||||
var B by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>J.staticN<!>
|
||||
var C by J.staticJ
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
// FULL_JDK
|
||||
// FILE: J.java
|
||||
import java.util.*;
|
||||
|
||||
public class J {
|
||||
@MyNonnull
|
||||
public static List<String> staticNN;
|
||||
@MyNullable
|
||||
public static List<String> staticN;
|
||||
public static List<String> staticJ;
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
class A : List<String> by J.staticNN
|
||||
class B : List<String> by J.staticN
|
||||
class C : List<String> by J.staticJ
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
@MyNonnull
|
||||
public static J staticNN;
|
||||
@MyNullable
|
||||
public static J staticN;
|
||||
public static J staticJ;
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
fun test() {
|
||||
val platformNN = J.staticNN
|
||||
val platformN = J.staticN
|
||||
val platformJ = J.staticJ
|
||||
|
||||
platformNN.foo()
|
||||
platformN<!UNSAFE_CALL!>.<!>foo()
|
||||
platformJ.foo()
|
||||
|
||||
with(platformNN) {
|
||||
foo()
|
||||
}
|
||||
with(platformN) {
|
||||
<!UNSAFE_CALL!>foo<!>()
|
||||
}
|
||||
with(platformJ) {
|
||||
foo()
|
||||
}
|
||||
|
||||
platformNN.bar()
|
||||
platformN.bar()
|
||||
platformJ.bar()
|
||||
}
|
||||
|
||||
fun J.foo() {}
|
||||
fun J?.bar() {}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
@MyNonnull
|
||||
public static J staticNN;
|
||||
@MyNullable
|
||||
public static J staticN;
|
||||
public static J staticJ;
|
||||
|
||||
public void foo() {}
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
fun test() {
|
||||
// @NotNull platform type
|
||||
val platformNN = J.staticNN
|
||||
// @Nullable platform type
|
||||
val platformN = J.staticN
|
||||
// platform type with no annotation
|
||||
val platformJ = J.staticJ
|
||||
|
||||
platformNN.foo()
|
||||
platformN<!UNSAFE_CALL!>.<!>foo()
|
||||
platformJ.foo()
|
||||
|
||||
with(platformNN) {
|
||||
foo()
|
||||
}
|
||||
with(platformN) {
|
||||
<!UNSAFE_CALL!>foo<!>()
|
||||
}
|
||||
with(platformJ) {
|
||||
foo()
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// !CHECK_TYPE
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
@MyNonnull
|
||||
public static J staticNN;
|
||||
@MyNullable
|
||||
public static J staticN;
|
||||
public static J staticJ;
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
fun test() {
|
||||
val platformNN = J.staticNN
|
||||
val platformN = J.staticN
|
||||
val platformJ = J.staticJ
|
||||
|
||||
checkSubtype<J>(platformNN)
|
||||
checkSubtype<J>(<!ARGUMENT_TYPE_MISMATCH!>platformN<!>)
|
||||
checkSubtype<J>(platformJ)
|
||||
|
||||
checkSubtype<J?>(platformNN)
|
||||
checkSubtype<J?>(platformN)
|
||||
checkSubtype<J?>(platformJ)
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: J.java
|
||||
import java.util.*;
|
||||
|
||||
public class J {
|
||||
@MyNonnull
|
||||
public static List<String> staticNN;
|
||||
@MyNullable
|
||||
public static List<String> staticN;
|
||||
public static List<String> staticJ;
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
fun test() {
|
||||
val platformNN = J.staticNN
|
||||
val platformN = J.staticN
|
||||
val platformJ = J.staticJ
|
||||
|
||||
for (x in platformNN) {}
|
||||
for (x in <!ITERATOR_ON_NULLABLE!>platformN<!>) {}
|
||||
for (x in platformJ) {}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
@MyNonnull
|
||||
public static J staticNN;
|
||||
@MyNullable
|
||||
public static J staticN;
|
||||
public static J staticJ;
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
fun test() {
|
||||
foo(J.staticNN)
|
||||
foo(<!ARGUMENT_TYPE_MISMATCH!>J.staticN<!>)
|
||||
foo(J.staticJ)
|
||||
|
||||
bar(J.staticNN)
|
||||
bar(J.staticN)
|
||||
bar(J.staticJ)
|
||||
}
|
||||
|
||||
fun foo(j: J) {}
|
||||
fun bar(j: J?) {}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
public interface Invoke {
|
||||
void invoke();
|
||||
}
|
||||
|
||||
@MyNonnull
|
||||
public static Invoke staticNN;
|
||||
@MyNullable
|
||||
public static Invoke staticN;
|
||||
public static Invoke staticJ;
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
fun test() {
|
||||
J.staticNN()
|
||||
J.<!UNSAFE_IMPLICIT_INVOKE_CALL!>staticN<!>()
|
||||
J.staticJ()
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// KT-6829 False warning on map to @Nullable
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
|
||||
@MyNullable
|
||||
public String method() { return ""; }
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
fun foo(collection: Collection<J>) {
|
||||
val mapped = collection.map { it.method() }
|
||||
mapped[0]<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
|
||||
public fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> {
|
||||
null!!
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
public interface Multi {
|
||||
String component1();
|
||||
String component2();
|
||||
}
|
||||
|
||||
@MyNonnull
|
||||
public static Multi staticNN;
|
||||
@MyNullable
|
||||
public static Multi staticN;
|
||||
public static Multi staticJ;
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
fun test() {
|
||||
val platformNN = J.staticNN
|
||||
val platformN = J.staticN
|
||||
val platformJ = J.staticJ
|
||||
|
||||
val (a1, b1) = platformNN
|
||||
val (a2, b2) = <!COMPONENT_FUNCTION_ON_NULLABLE, COMPONENT_FUNCTION_ON_NULLABLE!>platformN<!>
|
||||
val (a3, b3) = platformJ
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
@MyNonnull
|
||||
public static J staticNN;
|
||||
@MyNullable
|
||||
public static J staticN;
|
||||
public static J staticJ;
|
||||
|
||||
public static void staticSet(@MyNonnull J nn, @MyNullable J n, J j) {}
|
||||
|
||||
public J(@MyNonnull J nn, @MyNullable J n, J j) {}
|
||||
public J() {}
|
||||
|
||||
@MyNonnull
|
||||
public J nn;
|
||||
@MyNullable
|
||||
public J n;
|
||||
public J j;
|
||||
|
||||
public void set(@MyNonnull J nn, @MyNullable J n, J j) {}
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
fun test(n: J?, nn: J) {
|
||||
// @NotNull platform type
|
||||
val platformNN = J.staticNN
|
||||
// @Nullable platform type
|
||||
val platformN = J.staticN
|
||||
// platform type with no annotation
|
||||
val platformJ = J.staticJ
|
||||
|
||||
J.staticNN = <!ASSIGNMENT_TYPE_MISMATCH!>n<!>
|
||||
J.staticNN = <!ASSIGNMENT_TYPE_MISMATCH!>platformN<!>
|
||||
J.staticNN = nn
|
||||
J.staticNN = platformNN
|
||||
J.staticNN = platformJ
|
||||
|
||||
J.staticN = n
|
||||
J.staticN = platformN
|
||||
J.staticN = nn
|
||||
J.staticN = platformNN
|
||||
J.staticN = platformJ
|
||||
|
||||
J.staticJ = n
|
||||
J.staticJ = platformN
|
||||
J.staticJ = nn
|
||||
J.staticJ = platformNN
|
||||
J.staticJ = platformJ
|
||||
|
||||
J.staticSet(nn, nn, nn)
|
||||
J.staticSet(platformNN, platformNN, platformNN)
|
||||
J.staticSet(<!ARGUMENT_TYPE_MISMATCH!>n<!>, n, n)
|
||||
J.staticSet(<!ARGUMENT_TYPE_MISMATCH!>platformN<!>, platformN, platformN)
|
||||
J.staticSet(platformJ, platformJ, platformJ)
|
||||
|
||||
J().nn = <!ASSIGNMENT_TYPE_MISMATCH!>n<!>
|
||||
J().nn = <!ASSIGNMENT_TYPE_MISMATCH!>platformN<!>
|
||||
J().nn = nn
|
||||
J().nn = platformNN
|
||||
J().nn = platformJ
|
||||
|
||||
J().n = n
|
||||
J().n = platformN
|
||||
J().n = nn
|
||||
J().n = platformNN
|
||||
J().n = platformJ
|
||||
|
||||
J().j = n
|
||||
J().j = platformN
|
||||
J().j = nn
|
||||
J().j = platformNN
|
||||
J().j = platformJ
|
||||
|
||||
J().set(nn, nn, nn)
|
||||
J().set(platformNN, platformNN, platformNN)
|
||||
J().set(<!ARGUMENT_TYPE_MISMATCH!>n<!>, n, n)
|
||||
J().set(<!ARGUMENT_TYPE_MISMATCH!>platformN<!>, platformN, platformN)
|
||||
J().set(platformJ, platformJ, platformJ)
|
||||
|
||||
J(nn, nn, nn)
|
||||
J(platformNN, platformNN, platformNN)
|
||||
J(<!ARGUMENT_TYPE_MISMATCH!>n<!>, n, n)
|
||||
J(<!ARGUMENT_TYPE_MISMATCH!>platformN<!>, platformN, platformN)
|
||||
J(platformJ, platformJ, platformJ)
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
@MyNonnull
|
||||
public static int[] staticNN;
|
||||
@MyNullable
|
||||
public static int[] staticN;
|
||||
public static int[] staticJ;
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
fun test() {
|
||||
val platformNN = J.staticNN
|
||||
val platformN = J.staticN
|
||||
val platformJ = J.staticJ
|
||||
|
||||
platformNN[0]
|
||||
<!UNSAFE_CALL!>platformN[0]<!>
|
||||
platformJ[0]
|
||||
|
||||
platformNN[0] = 1
|
||||
<!UNSAFE_CALL!>platformN[0]<!> = 1
|
||||
platformJ[0] = 1
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
@MyNonnull
|
||||
public static Exception staticNN;
|
||||
@MyNullable
|
||||
public static Exception staticN;
|
||||
public static Exception staticJ;
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
fun test() {
|
||||
throw J.staticNN
|
||||
}
|
||||
|
||||
fun test1() {
|
||||
throw J.staticN
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
throw J.staticJ
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: J.java
|
||||
public class J {
|
||||
@MyNullable
|
||||
public static J staticN;
|
||||
}
|
||||
|
||||
// FILE: JJ.java
|
||||
public class JJ {
|
||||
public static JJ staticNN;
|
||||
}
|
||||
|
||||
// FILE: JJJ.java
|
||||
public class JJJ {
|
||||
@MyNonnull
|
||||
public static JJJ staticNNN;
|
||||
}
|
||||
|
||||
// FILE: k.kt
|
||||
fun test() {
|
||||
val a = J.staticN <!USELESS_ELVIS_RIGHT_IS_NULL!>?: null<!>
|
||||
foo(a)
|
||||
val b = JJ.staticNN <!USELESS_ELVIS_RIGHT_IS_NULL!>?: null<!>
|
||||
foo(b)
|
||||
val c = JJJ.staticNNN <!USELESS_ELVIS!>?: null<!>
|
||||
foo(c)
|
||||
}
|
||||
|
||||
fun foo(a: Any?) {
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_EXPRESSION
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: MyNotNull.java
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierNickname;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.METHOD, ElementType.PARAMETER})
|
||||
@Nonnull
|
||||
@TypeQualifierNickname
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MyNotNull {}
|
||||
|
||||
|
||||
// FILE: AnnotatedWithJsr.java
|
||||
public class AnnotatedWithJsr {
|
||||
@MyNotNull
|
||||
public String getString() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void consumeString(@MyNotNull String s) { }
|
||||
}
|
||||
|
||||
|
||||
|
||||
// FILE: AnnotatedWithJB.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AnnotatedWithJB {
|
||||
public @NotNull String getString() {
|
||||
return "hello";
|
||||
}
|
||||
|
||||
public void consumeString(@NotNull String s) { }
|
||||
}
|
||||
|
||||
|
||||
// FILE: PlainJava.java
|
||||
public class PlainJava {
|
||||
public String getString() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void consumeString(String s) { }
|
||||
}
|
||||
|
||||
|
||||
// FILE: main.kt
|
||||
val jsr: AnnotatedWithJsr = AnnotatedWithJsr()
|
||||
val jsrNullable: AnnotatedWithJsr? = null
|
||||
|
||||
val jb: AnnotatedWithJB = AnnotatedWithJB()
|
||||
val jbNullable: AnnotatedWithJB? = null
|
||||
|
||||
val platform: PlainJava = PlainJava()
|
||||
val platformNullable: PlainJava? = null
|
||||
|
||||
val a = jsr.string
|
||||
val b = jsrNullable?.string
|
||||
val c = jb.string
|
||||
val d = jbNullable?.string
|
||||
val e = platform.string
|
||||
val f = platformNullable?.string
|
||||
|
||||
fun evlis() {
|
||||
// JSR
|
||||
val r1 = a <!USELESS_ELVIS!>?: ""<!>
|
||||
val r2 = b ?: ""
|
||||
|
||||
// JB
|
||||
val r3 = c <!USELESS_ELVIS!>?: ""<!>
|
||||
val r4 = d ?: ""
|
||||
|
||||
// Platform
|
||||
val r5 = e ?: ""
|
||||
val r6 = f ?: ""
|
||||
}
|
||||
|
||||
fun ifChecksAndSmartCasts() {
|
||||
// JSR
|
||||
val r1 = if (a == null) 42 else a.length
|
||||
val r2 = if (b == null) 42 else b.length
|
||||
|
||||
// JB
|
||||
val r3 = if (c == null) 42 else c.length
|
||||
val r4 = if (d == null) 42 else d.length
|
||||
|
||||
// Platform
|
||||
val r5 = if (e == null) 42 else e.length
|
||||
val r6 = if (f == null) 42 else f.length
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: A.java
|
||||
public class A<T> {
|
||||
public void foo(@MyNonnull T t) {
|
||||
}
|
||||
|
||||
public @MyNullable String bar() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public @MyNullable T bam() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@MyNullable
|
||||
public <X> X baz() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
// FILE: main.kt
|
||||
class X<T>(t: T?) {
|
||||
|
||||
init {
|
||||
val a = A<T>()
|
||||
a.foo(<!ARGUMENT_TYPE_MISMATCH!>t<!>)
|
||||
|
||||
val x: T = <!INITIALIZER_TYPE_MISMATCH, TYPE_MISMATCH!>a.bam()<!>
|
||||
val y: T = <!INITIALIZER_TYPE_MISMATCH, TYPE_MISMATCH!>a.baz<T>()<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val a = A<String?>()
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
|
||||
val b: String = <!INITIALIZER_TYPE_MISMATCH, TYPE_MISMATCH!>a.bar()<!>
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: MyNullable.java
|
||||
import javax.annotation.*;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import javax.annotation.meta.TypeQualifierNickname;
|
||||
import javax.annotation.meta.When;
|
||||
|
||||
@Documented
|
||||
@TypeQualifierNickname
|
||||
@Nonnull(when = When.MAYBE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MyNullable {
|
||||
|
||||
}
|
||||
|
||||
// FILE: MyCheckForNull.java
|
||||
import javax.annotation.*;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import javax.annotation.meta.TypeQualifierNickname;
|
||||
import javax.annotation.meta.When;
|
||||
|
||||
@Documented
|
||||
@TypeQualifierNickname
|
||||
@CheckForNull
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MyCheckForNull {
|
||||
|
||||
}
|
||||
|
||||
// FILE: MyNonnull.java
|
||||
import javax.annotation.*;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import javax.annotation.meta.TypeQualifierNickname;
|
||||
import javax.annotation.meta.When;
|
||||
|
||||
@Documented
|
||||
@TypeQualifierNickname
|
||||
@Nonnull(when = When.ALWAYS)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MyNonnull {
|
||||
|
||||
}
|
||||
|
||||
// FILE: A.java
|
||||
import javax.annotation.*;
|
||||
|
||||
public class A {
|
||||
@MyNullable public String field = null;
|
||||
|
||||
@MyNullable
|
||||
public String foo(@MyNonnull String x, @MyNullable CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MyNonnull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MyCheckForNull
|
||||
public String baz(@MyNonnull String x, @MyCheckForNull CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.baz("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
Vendored
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
|
||||
Vendored
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
|
||||
Vendored
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: spr/NonNullApi.java
|
||||
package spr;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Nonnull
|
||||
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER})
|
||||
public @interface NonNullApi {
|
||||
}
|
||||
|
||||
// FILE: A.java
|
||||
import spr.*;
|
||||
|
||||
@NonNullApi
|
||||
public class A {
|
||||
public String getBar() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A) {
|
||||
if (a.getBar() == "1" && a.hashCode() != 0) return
|
||||
if (a.getBar() != "2" && a.hashCode() != 0) return
|
||||
|
||||
if (a.getBar() == null && a.hashCode() != 0) return
|
||||
if (a.getBar() != null && a.hashCode() != 0) return
|
||||
|
||||
if (a.bar == "1" && a.hashCode() != 0) return
|
||||
if (a.bar != "2" && a.hashCode() != 0) return
|
||||
|
||||
if (a.bar == null && a.hashCode() != 0) return
|
||||
if (a.bar != null && a.hashCode() != 0) return
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: FieldsAreNullable.java
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@CheckForNull
|
||||
@TypeQualifierDefault({ElementType.FIELD})
|
||||
public @interface FieldsAreNullable {
|
||||
}
|
||||
|
||||
// FILE: A.java
|
||||
import javax.annotation.*;
|
||||
|
||||
@FieldsAreNullable
|
||||
public class A {
|
||||
public String field = null;
|
||||
@Nonnull
|
||||
public String nonNullField = "";
|
||||
|
||||
public String foo(String q, @Nonnull String x, @CheckForNull CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A) {
|
||||
// foo is platform
|
||||
a.foo("", "", null)?.length
|
||||
a.foo("", "", null).length
|
||||
a.foo(null, <!NULL_FOR_NONNULL_TYPE!>null<!>, "").length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
a.field = null
|
||||
|
||||
a.nonNullField<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
a.nonNullField.length
|
||||
a.nonNullField = <!NULL_FOR_NONNULL_TYPE!>null<!>
|
||||
}
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: NonNullApi.java
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Nonnull
|
||||
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
|
||||
public @interface NonNullApi {
|
||||
}
|
||||
|
||||
// FILE: NullableApi.java
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@CheckForNull
|
||||
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
|
||||
public @interface NullableApi {
|
||||
}
|
||||
|
||||
// FILE: A.java
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@NonNullApi
|
||||
public class A {
|
||||
public String foo1(String x) { return ""; }
|
||||
public String foo2(String x) { return ""; }
|
||||
public String foo3(String x) { return ""; }
|
||||
|
||||
|
||||
@Nullable
|
||||
public String bar1(@Nullable String x) { return ""; }
|
||||
@Nullable
|
||||
public String bar2(@Nullable String x) { return ""; }
|
||||
|
||||
public String baz(@Nonnull String x) { return ""; }
|
||||
}
|
||||
|
||||
// FILE: AInt.java
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@NonNullApi
|
||||
public interface AInt {
|
||||
public CharSequence foo1(String x);
|
||||
public CharSequence foo2(String x);
|
||||
public CharSequence foo3(String x);
|
||||
|
||||
|
||||
@Nullable
|
||||
public CharSequence bar1(@Nullable String x);
|
||||
@Nullable
|
||||
public CharSequence bar2(@Nullable String x);
|
||||
|
||||
public CharSequence baz(@Nonnull String x);
|
||||
}
|
||||
|
||||
|
||||
// FILE: B.java
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@NullableApi
|
||||
public class B extends A implements AInt {
|
||||
// conflicts
|
||||
public String foo1(String x) { return ""; }
|
||||
|
||||
// no conflicts
|
||||
@Nonnull
|
||||
public String foo2(@Nonnull String x) { return ""; }
|
||||
|
||||
// fake override for foo3 shouldn't have any conflicts
|
||||
|
||||
// no conflicts
|
||||
public String bar1(String x) { return ""; }
|
||||
|
||||
// conflicts
|
||||
public String baz(String x) { return ""; }
|
||||
}
|
||||
|
||||
// FILE: C.java
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@NonNullApi
|
||||
public class C extends A implements AInt {
|
||||
// no conflicts
|
||||
public String foo1(String x) { return ""; }
|
||||
|
||||
// no conflicts
|
||||
public String foo2(@Nonnull String x) { return ""; }
|
||||
|
||||
// fake override for foo3 shouldn't have any conflicts
|
||||
|
||||
// no conflicts, covariant override
|
||||
public String bar1(String x) { return ""; }
|
||||
// no conflicts
|
||||
@Nullable
|
||||
public String bar2(@Nullable String x) { return ""; }
|
||||
|
||||
// no conflicts
|
||||
public String baz(String x) { return ""; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A, b: B, c: C) {
|
||||
a.foo1(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
a.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
a.foo3(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
a.bar1(null)<!UNSAFE_CALL!>.<!>length
|
||||
a.bar2(null)<!UNSAFE_CALL!>.<!>length
|
||||
a.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
|
||||
b.foo1(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
b.foo1(<!NULL_FOR_NONNULL_TYPE!>null<!>)<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
b.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
b.foo3(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
b.bar1(null)<!UNSAFE_CALL!>.<!>length
|
||||
b.bar2(null)<!UNSAFE_CALL!>.<!>length
|
||||
b.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
b.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
|
||||
c.foo1(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
c.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
c.foo3(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
c.bar1(null)<!UNSAFE_CALL!>.<!>length
|
||||
c.bar1(null)?.length
|
||||
c.bar2(null)<!UNSAFE_CALL!>.<!>length
|
||||
c.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
}
|
||||
+181
@@ -0,0 +1,181 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: NonNullApi.java
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Nonnull
|
||||
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
|
||||
public @interface NonNullApi {
|
||||
}
|
||||
|
||||
// FILE: NullableApi.java
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@CheckForNull
|
||||
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
|
||||
public @interface NullableApi {
|
||||
}
|
||||
|
||||
// FILE: FieldsAreNullable.java
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@CheckForNull
|
||||
@TypeQualifierDefault({ElementType.FIELD})
|
||||
public @interface FieldsAreNullable {
|
||||
}
|
||||
|
||||
// FILE: A.java
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@NonNullApi
|
||||
public class A {
|
||||
public String field = null;
|
||||
|
||||
public String foo(String x, @CheckForNull CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@NullableApi
|
||||
public String foobar(String x, @Nonnull CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public java.util.List<String> baz() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NullableApi
|
||||
public class B {
|
||||
public String field = null;
|
||||
|
||||
public String foo(String x, @Nonnull CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@NonNullApi
|
||||
public String foobar(String x, @Nullable CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public java.util.List<String> baz() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@FieldsAreNullable
|
||||
public class C {
|
||||
public String field = null;
|
||||
|
||||
public String foo(String x, @Nullable CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@NullableApi
|
||||
public String foobar(String x, @Nullable CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public java.util.List<String> baz() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A, b: A.B, c: A.C) {
|
||||
a.foo("", null)<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
a.foo("", null).length
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "").length
|
||||
|
||||
a.foobar(null, "")<!UNSAFE_CALL!>.<!>length
|
||||
a.foobar("", <!NULL_FOR_NONNULL_TYPE!>null<!>)?.length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
a.field.length
|
||||
|
||||
a.baz()<!UNSAFE_CALL!>.<!>get(0)
|
||||
a.baz()!!.get(0).get(0)
|
||||
a.baz()!!.get(0)?.get(0)
|
||||
|
||||
// b
|
||||
b.foo("", <!NULL_FOR_NONNULL_TYPE!>null<!>)?.length
|
||||
b.foo("", <!NULL_FOR_NONNULL_TYPE!>null<!>)<!UNSAFE_CALL!>.<!>length
|
||||
b.foo(null, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
b.foobar(<!NULL_FOR_NONNULL_TYPE!>null<!>, "").length
|
||||
b.foobar("", null)<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
|
||||
b.bar()<!UNSAFE_CALL!>.<!>length
|
||||
b.bar()!!.length
|
||||
|
||||
b.field?.length
|
||||
b.field<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
b.baz()<!UNSAFE_CALL!>.<!>get(0)
|
||||
b.baz()!!.get(0).get(0)
|
||||
b.baz()!!.get(0)?.get(0)
|
||||
|
||||
// c
|
||||
c.foo("", null)?.length
|
||||
c.foo("", null).length
|
||||
c.foo(null, "").length
|
||||
|
||||
c.foobar(null, "")<!UNSAFE_CALL!>.<!>length
|
||||
c.foobar("", null)?.length
|
||||
|
||||
c.bar().length
|
||||
c.bar()!!.length
|
||||
|
||||
c.field?.length
|
||||
c.field<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
c.baz()<!UNSAFE_CALL!>.<!>get(0)
|
||||
c.baz()!!.get(0).get(0)
|
||||
c.baz()!!.get(0)?.get(0)
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: A.java
|
||||
import javax.annotation.*;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public class A {
|
||||
@Nullable public String field = null;
|
||||
|
||||
public String foo(String q, @Nonnull String x, @CheckForNull CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A) {
|
||||
// foo is platform
|
||||
a.foo("", "", null)?.length
|
||||
a.foo("", "", null).length
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, <!NULL_FOR_NONNULL_TYPE!>null<!>, "").length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: test/package-info.java
|
||||
@javax.annotation.ParametersAreNonnullByDefault()
|
||||
package test;
|
||||
|
||||
// FILE: test/A.java
|
||||
package test;
|
||||
|
||||
import javax.annotation.*;
|
||||
|
||||
public class A {
|
||||
@Nullable public String field = null;
|
||||
|
||||
public String foo(String q, @Nonnull String x, @CheckForNull CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test2/A2.java
|
||||
package test2;
|
||||
|
||||
import javax.annotation.*;
|
||||
|
||||
public class A2 {
|
||||
@Nullable public String field = null;
|
||||
|
||||
public String foo(String q, @Nonnull String x, @CheckForNull CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import test.A
|
||||
import test2.A2
|
||||
|
||||
fun main(a: A, a2: A2) {
|
||||
a.foo("", "", null)?.length
|
||||
a.foo("", "", null).length
|
||||
a.foo(null, <!NULL_FOR_NONNULL_TYPE!>null<!>, "").length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a2.foo("", "", null)?.length
|
||||
a2.foo("", "", null).length
|
||||
a2.foo(null, <!NULL_FOR_NONNULL_TYPE!>null<!>, "").length
|
||||
|
||||
a2.bar().length
|
||||
a2.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a2.field?.length
|
||||
a2.field<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: spr/Nullable.java
|
||||
package spr;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierNickname;
|
||||
import javax.annotation.meta.When;
|
||||
|
||||
@Target({ElementType.METHOD, ElementType.PARAMETER})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Nonnull(when = When.MAYBE)
|
||||
@TypeQualifierNickname
|
||||
public @interface Nullable {
|
||||
}
|
||||
|
||||
// FILE: spr/NonNullApi.java
|
||||
package spr;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Nonnull
|
||||
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER})
|
||||
public @interface NonNullApi {
|
||||
}
|
||||
|
||||
// FILE: A.java
|
||||
import spr.*;
|
||||
|
||||
@NonNullApi
|
||||
public class A {
|
||||
public String field = null;
|
||||
|
||||
public String foo(String x, @Nullable CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public java.util.List<String> baz() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A) {
|
||||
a.foo("", null)<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
a.foo("", null).length
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "").length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field.length
|
||||
|
||||
a.baz()<!UNSAFE_CALL!>.<!>get(0)
|
||||
a.baz()!!.get(0).get(0)
|
||||
a.baz()!!.get(0)?.get(0)
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: spr/Nullable.java
|
||||
package spr;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierNickname;
|
||||
import javax.annotation.meta.When;
|
||||
|
||||
@Target({ElementType.METHOD, ElementType.PARAMETER})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Nonnull(when = When.MAYBE)
|
||||
@TypeQualifierNickname
|
||||
public @interface Nullable {
|
||||
}
|
||||
|
||||
// FILE: spr/NonNullApi.java
|
||||
package spr;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Target(ElementType.PACKAGE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Nonnull
|
||||
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER})
|
||||
public @interface NonNullApi {
|
||||
}
|
||||
|
||||
// FILE: test/package-info.java
|
||||
@spr.NonNullApi()
|
||||
package test;
|
||||
|
||||
// FILE: test/A.java
|
||||
package test;
|
||||
|
||||
import spr.*;
|
||||
|
||||
public class A {
|
||||
public String field = null;
|
||||
|
||||
public String foo(String x, @Nullable CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public java.util.List<String> baz() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: test.A) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null).length
|
||||
a.foo(null, "").length
|
||||
|
||||
a.bar().length
|
||||
a.bar()!!.length
|
||||
|
||||
a.field?.length
|
||||
a.field.length
|
||||
|
||||
a.baz()<!UNSAFE_CALL!>.<!>get(0)
|
||||
a.baz()!!.get(0).get(0)
|
||||
a.baz()!!.get(0)?.get(0)
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: strict
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: strict
|
||||
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: strict
|
||||
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: strict
|
||||
|
||||
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: strict
|
||||
|
||||
// FILE: spr/NonNullApi.java
|
||||
package spr;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Nonnull
|
||||
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER})
|
||||
public @interface NonNullApi {
|
||||
}
|
||||
|
||||
// FILE: spr/UnknownNullability.java
|
||||
package spr;
|
||||
|
||||
import javax.annotation.*;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import javax.annotation.meta.TypeQualifierNickname;
|
||||
import javax.annotation.meta.When;
|
||||
|
||||
@Documented
|
||||
@TypeQualifierNickname
|
||||
@Nonnull(when = When.UNKNOWN)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface UnknownNullability {
|
||||
|
||||
}
|
||||
|
||||
// FILE: spr/ForceFlexibility.java
|
||||
package spr;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
import javax.annotation.meta.When;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@UnknownNullability
|
||||
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER})
|
||||
public @interface ForceFlexibility {
|
||||
}
|
||||
|
||||
// FILE: B.java
|
||||
public interface B {
|
||||
public void foo(@javax.annotation.Nonnull String x);
|
||||
public void bar(@javax.annotation.Nonnull String x);
|
||||
public void baz(@javax.annotation.Nonnull String x);
|
||||
public void foobar(@javax.annotation.Nonnull String x);
|
||||
}
|
||||
|
||||
// FILE: A.java
|
||||
import spr.*;
|
||||
|
||||
@NonNullApi
|
||||
public class A implements B {
|
||||
@ForceFlexibility
|
||||
public void foo(String x) {}
|
||||
public void bar(@ForceFlexibility String x) {}
|
||||
public void baz(@UnknownNullability String x) {}
|
||||
public void foobar(@javax.annotation.Nonnull(when = javax.annotation.meta.When.UNKNOWN) String x) {}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A, b: B) {
|
||||
b.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
b.bar(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
b.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
b.foobar(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
a.bar(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
a.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
a.foobar(null)
|
||||
}
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: strict
|
||||
|
||||
// FILE: NonNullApi.java
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Nonnull
|
||||
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
|
||||
public @interface NonNullApi {
|
||||
}
|
||||
|
||||
// FILE: NullableApi.java
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@CheckForNull
|
||||
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
|
||||
public @interface NullableApi {
|
||||
}
|
||||
|
||||
// FILE: A.java
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@NonNullApi
|
||||
public class A {
|
||||
public String foo1(String x) { return ""; }
|
||||
public String foo2(String x) { return ""; }
|
||||
public String foo3(String x) { return ""; }
|
||||
|
||||
|
||||
@Nullable
|
||||
public String bar1(@Nullable String x) { return ""; }
|
||||
@Nullable
|
||||
public String bar2(@Nullable String x) { return ""; }
|
||||
|
||||
public String baz(@Nonnull String x) { return ""; }
|
||||
}
|
||||
|
||||
// FILE: AInt.java
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@NonNullApi
|
||||
public interface AInt {
|
||||
public CharSequence foo1(String x);
|
||||
public CharSequence foo2(String x);
|
||||
public CharSequence foo3(String x);
|
||||
|
||||
|
||||
@Nullable
|
||||
public CharSequence bar1(@Nullable String x);
|
||||
@Nullable
|
||||
public CharSequence bar2(@Nullable String x);
|
||||
|
||||
public CharSequence baz(@Nonnull String x);
|
||||
}
|
||||
|
||||
|
||||
// FILE: B.java
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@NullableApi
|
||||
public class B extends A implements AInt {
|
||||
// conflicts
|
||||
public String foo1(String x) { return ""; }
|
||||
|
||||
// no conflicts
|
||||
@Nonnull
|
||||
public String foo2(@Nonnull String x) { return ""; }
|
||||
|
||||
// fake override for foo3 shouldn't have any conflicts
|
||||
|
||||
// no conflicts
|
||||
public String bar1(String x) { return ""; }
|
||||
|
||||
// conflicts
|
||||
public String baz(String x) { return ""; }
|
||||
}
|
||||
|
||||
// FILE: C.java
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@NonNullApi
|
||||
public class C extends A implements AInt {
|
||||
// no conflicts
|
||||
public String foo1(String x) { return ""; }
|
||||
|
||||
// no conflicts
|
||||
public String foo2(@Nonnull String x) { return ""; }
|
||||
|
||||
// fake override for foo3 shouldn't have any conflicts
|
||||
|
||||
// no conflicts, covariant override
|
||||
public String bar1(String x) { return ""; }
|
||||
// no conflicts
|
||||
@Nullable
|
||||
public String bar2(@Nullable String x) { return ""; }
|
||||
|
||||
// no conflicts
|
||||
public String baz(String x) { return ""; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A, b: B, c: C) {
|
||||
a.foo1(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
a.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
a.foo3(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
a.bar1(null)<!UNSAFE_CALL!>.<!>length
|
||||
a.bar2(null)<!UNSAFE_CALL!>.<!>length
|
||||
a.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
|
||||
b.foo1(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
b.foo1(<!NULL_FOR_NONNULL_TYPE!>null<!>)<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
b.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
b.foo3(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
b.bar1(null)<!UNSAFE_CALL!>.<!>length
|
||||
b.bar2(null)<!UNSAFE_CALL!>.<!>length
|
||||
b.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
b.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
|
||||
c.foo1(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
c.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
c.foo3(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
c.bar1(null)<!UNSAFE_CALL!>.<!>length
|
||||
c.bar1(null)?.length
|
||||
c.bar2(null)<!UNSAFE_CALL!>.<!>length
|
||||
c.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
}
|
||||
+181
@@ -0,0 +1,181 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: strict
|
||||
|
||||
// FILE: NonNullApi.java
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Nonnull
|
||||
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
|
||||
public @interface NonNullApi {
|
||||
}
|
||||
|
||||
// FILE: NullableApi.java
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@CheckForNull
|
||||
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
|
||||
public @interface NullableApi {
|
||||
}
|
||||
|
||||
// FILE: FieldsAreNullable.java
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@CheckForNull
|
||||
@TypeQualifierDefault({ElementType.FIELD})
|
||||
public @interface FieldsAreNullable {
|
||||
}
|
||||
|
||||
// FILE: A.java
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@NonNullApi
|
||||
public class A {
|
||||
public String field = null;
|
||||
|
||||
public String foo(String x, @CheckForNull CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@NullableApi
|
||||
public String foobar(String x, @NonNullApi CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public java.util.List<String> baz() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NullableApi
|
||||
public class B {
|
||||
public String field = null;
|
||||
|
||||
public String foo(String x, @Nonnull CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@NonNullApi
|
||||
public String foobar(String x, @NullableApi CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public java.util.List<String> baz() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@FieldsAreNullable
|
||||
public class C {
|
||||
public String field = null;
|
||||
|
||||
public String foo(String x, @Nullable CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@NullableApi
|
||||
public String foobar(String x, @Nullable CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public java.util.List<String> baz() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A, b: A.B, c: A.C) {
|
||||
a.foo("", null)<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
a.foo("", null).length
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "").length
|
||||
|
||||
a.foobar(null, "")<!UNSAFE_CALL!>.<!>length
|
||||
a.foobar("", <!NULL_FOR_NONNULL_TYPE!>null<!>)?.length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
a.field.length
|
||||
|
||||
a.baz()<!UNSAFE_CALL!>.<!>get(0)
|
||||
a.baz()!!.get(0).get(0)
|
||||
a.baz()!!.get(0)?.get(0)
|
||||
|
||||
// b
|
||||
b.foo("", <!NULL_FOR_NONNULL_TYPE!>null<!>)?.length
|
||||
b.foo("", <!NULL_FOR_NONNULL_TYPE!>null<!>)<!UNSAFE_CALL!>.<!>length
|
||||
b.foo(null, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
b.foobar(<!NULL_FOR_NONNULL_TYPE!>null<!>, "").length
|
||||
b.foobar("", null)<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
|
||||
b.bar()<!UNSAFE_CALL!>.<!>length
|
||||
b.bar()!!.length
|
||||
|
||||
b.field?.length
|
||||
b.field<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
b.baz()<!UNSAFE_CALL!>.<!>get(0)
|
||||
b.baz()!!.get(0).get(0)
|
||||
b.baz()!!.get(0)?.get(0)
|
||||
|
||||
// c
|
||||
c.foo("", null)?.length
|
||||
c.foo("", null).length
|
||||
c.foo(null, "").length
|
||||
|
||||
c.foobar(null, "")<!UNSAFE_CALL!>.<!>length
|
||||
c.foobar("", null)?.length
|
||||
|
||||
c.bar().length
|
||||
c.bar()!!.length
|
||||
|
||||
c.field?.length
|
||||
c.field<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
c.baz()<!UNSAFE_CALL!>.<!>get(0)
|
||||
c.baz()!!.get(0).get(0)
|
||||
c.baz()!!.get(0)?.get(0)
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: strict
|
||||
|
||||
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: strict
|
||||
|
||||
// RENDER_PACKAGE: test, test2
|
||||
|
||||
// FILE: test/package-info.java
|
||||
@javax.annotation.ParametersAreNonnullByDefault()
|
||||
package test;
|
||||
|
||||
// FILE: test/A.java
|
||||
package test;
|
||||
|
||||
import javax.annotation.*;
|
||||
|
||||
public class A {
|
||||
@Nullable public String field = null;
|
||||
|
||||
public String foo(String q, @Nonnull String x, @CheckForNull CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test2/A2.java
|
||||
package test2;
|
||||
|
||||
import javax.annotation.*;
|
||||
|
||||
public class A2 {
|
||||
@Nullable public String field = null;
|
||||
|
||||
public String foo(String q, @Nonnull String x, @CheckForNull CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import test.A
|
||||
import test2.A2
|
||||
|
||||
fun main(a: A, a2: A2) {
|
||||
a.foo("", "", null)?.length
|
||||
a.foo("", "", null).length
|
||||
a.foo(null, <!NULL_FOR_NONNULL_TYPE!>null<!>, "").length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a2.foo("", "", null)?.length
|
||||
a2.foo("", "", null).length
|
||||
a2.foo(null, <!NULL_FOR_NONNULL_TYPE!>null<!>, "").length
|
||||
|
||||
a2.bar().length
|
||||
a2.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a2.field?.length
|
||||
a2.field<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: strict
|
||||
|
||||
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: strict
|
||||
// RENDER_PACKAGE: test
|
||||
|
||||
// FILE: spr/Nullable.java
|
||||
package spr;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierNickname;
|
||||
import javax.annotation.meta.When;
|
||||
|
||||
@Target({ElementType.METHOD, ElementType.PARAMETER})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Nonnull(when = When.MAYBE)
|
||||
@TypeQualifierNickname
|
||||
public @interface Nullable {
|
||||
}
|
||||
|
||||
// FILE: spr/NonNullApi.java
|
||||
package spr;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Target(ElementType.PACKAGE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Nonnull
|
||||
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER})
|
||||
public @interface NonNullApi {
|
||||
}
|
||||
|
||||
// FILE: test/package-info.java
|
||||
@spr.NonNullApi()
|
||||
package test;
|
||||
|
||||
// FILE: test/A.java
|
||||
package test;
|
||||
|
||||
import spr.*;
|
||||
|
||||
public class A {
|
||||
public String field = null;
|
||||
|
||||
public String foo(String x, @Nullable CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public java.util.List<String> baz() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: test.A) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null).length
|
||||
a.foo(null, "").length
|
||||
|
||||
a.bar().length
|
||||
a.bar()!!.length
|
||||
|
||||
a.field?.length
|
||||
a.field.length
|
||||
|
||||
a.baz()<!UNSAFE_CALL!>.<!>get(0)
|
||||
a.baz()!!.get(0).get(0)
|
||||
a.baz()!!.get(0)?.get(0)
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: ignore
|
||||
|
||||
// FILE: MyErrorNonnull.java
|
||||
import javax.annotation.*;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import javax.annotation.meta.TypeQualifierNickname;
|
||||
import javax.annotation.meta.When;
|
||||
|
||||
import kotlin.annotations.jvm.*;
|
||||
|
||||
@Documented
|
||||
@TypeQualifierNickname
|
||||
@Nonnull(when = When.ALWAYS)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@UnderMigration(status = MigrationStatus.STRICT)
|
||||
public @interface MyErrorNonnull {
|
||||
}
|
||||
|
||||
// FILE: MyWarnNonnull.java
|
||||
import javax.annotation.*;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import javax.annotation.meta.TypeQualifierNickname;
|
||||
import javax.annotation.meta.When;
|
||||
|
||||
import kotlin.annotations.jvm.*;
|
||||
|
||||
@Documented
|
||||
@TypeQualifierNickname
|
||||
@Nonnull(when = When.ALWAYS)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@UnderMigration(status = MigrationStatus.WARN)
|
||||
public @interface MyWarnNonnull {
|
||||
}
|
||||
|
||||
// FILE: MyIgnoreNonnull.java
|
||||
import javax.annotation.*;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import javax.annotation.meta.TypeQualifierNickname;
|
||||
import javax.annotation.meta.When;
|
||||
|
||||
import kotlin.annotations.jvm.*;
|
||||
|
||||
@Documented
|
||||
@TypeQualifierNickname
|
||||
@Nonnull(when = When.ALWAYS)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@UnderMigration(status = MigrationStatus.IGNORE)
|
||||
public @interface MyIgnoreNonnull {
|
||||
}
|
||||
|
||||
// FILE: A.java
|
||||
public class A {
|
||||
public void foo(@MyErrorNonnull String bar) {}
|
||||
public void foo2(@MyWarnNonnull String bar) {}
|
||||
public void foo3(@MyIgnoreNonnull String bar) {}
|
||||
public void foo4(@MyMigrationNonnull String bar) {}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A) {
|
||||
a.foo("")
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
|
||||
a.foo2("")
|
||||
a.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
|
||||
a.foo3("")
|
||||
a.foo3(null)
|
||||
|
||||
a.foo4("")
|
||||
a.foo4(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: ignore
|
||||
// JSR305_MIGRATION_REPORT: strict
|
||||
// JSR305_SPECIAL_REPORT: MyNonnull:warn
|
||||
|
||||
// FILE: A.java
|
||||
import javax.annotation.*;
|
||||
|
||||
public class A {
|
||||
@MyMigrationNullable public String field = null;
|
||||
|
||||
@MyMigrationNullable
|
||||
public String foo(@MyMigrationNonnull String x, CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MyMigrationNonnull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MyNullable public String field2 = null;
|
||||
@MyNullable
|
||||
public String foo2(@MyNonnull String x, CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MyNonnull
|
||||
public String bar2() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.foo2("", null)?.length
|
||||
a.foo2("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar2().length
|
||||
a.bar2()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field2?.length
|
||||
a.field2<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
// JSR305_MIGRATION_REPORT: ignore
|
||||
// JSR305_SPECIAL_REPORT: MyNullable:strict, MyMigrationNonnull:strict
|
||||
|
||||
// FILE: A.java
|
||||
import javax.annotation.*;
|
||||
|
||||
public class A {
|
||||
@MyMigrationNullable public String field = null;
|
||||
|
||||
@MyMigrationNullable
|
||||
public String foo(@MyMigrationNonnull String x, CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MyMigrationNonnull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MyNullable public String field2 = null;
|
||||
@MyNullable
|
||||
public String foo2(@MyNonnull String x, CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MyNonnull
|
||||
public String bar2() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.foo2("", null)?.length
|
||||
a.foo2("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar2().length
|
||||
a.bar2()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field2?.length
|
||||
a.field2<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
// JSR305_MIGRATION_REPORT: strict
|
||||
// JSR305_SPECIAL_REPORT: MyNonnull:ignore, MySuperNull:strict
|
||||
|
||||
// FILE: MySuperNull.java
|
||||
import javax.annotation.*;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import javax.annotation.meta.TypeQualifierNickname;
|
||||
import javax.annotation.meta.When;
|
||||
|
||||
@Documented
|
||||
@TypeQualifierNickname
|
||||
@Nonnull(when = When.MAYBE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MySuperNull {
|
||||
}
|
||||
|
||||
// FILE: A.java
|
||||
import javax.annotation.*;
|
||||
|
||||
public class A {
|
||||
@MyMigrationNullable public String field = null;
|
||||
|
||||
@MyMigrationNullable
|
||||
public String foo(@MyMigrationNonnull String x, CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MyMigrationNonnull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MyNullable public String field2 = null;
|
||||
@MyNullable
|
||||
public String foo2(@MyNonnull String x, CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MyNonnull
|
||||
public String bar2() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MySuperNull public String field3 = null;
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.foo2("", null)?.length
|
||||
a.foo2("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar2().length
|
||||
a.bar2()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field2?.length
|
||||
a.field2<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.field3?.length
|
||||
a.field3<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: strict
|
||||
// JSR305_MIGRATION_REPORT: ignore
|
||||
// JSR305_SPECIAL_REPORT: MyNullable:warn, MyMigrationNonnull:strict
|
||||
|
||||
// FILE: A.java
|
||||
import javax.annotation.*;
|
||||
|
||||
public class A {
|
||||
@MyMigrationNullable public String field = null;
|
||||
|
||||
@MyMigrationNullable
|
||||
public String foo(@MyMigrationNonnull String x, CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MyMigrationNonnull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MyNullable public String field2 = null;
|
||||
@MyNullable
|
||||
public String foo2(@MyNonnull String x, CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MyNonnull
|
||||
public String bar2() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.foo2("", null)?.length
|
||||
a.foo2("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar2().length
|
||||
a.bar2()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field2?.length
|
||||
a.field2<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: strict
|
||||
// JSR305_MIGRATION_REPORT: warn
|
||||
// JSR305_SPECIAL_REPORT: MyNullable:ignore, MyMigrationNullable:strict
|
||||
|
||||
// FILE: A.java
|
||||
import javax.annotation.*;
|
||||
|
||||
public class A {
|
||||
@MyMigrationNullable public String field = null;
|
||||
|
||||
@MyMigrationNullable
|
||||
public String foo(@MyMigrationNonnull String x, CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MyMigrationNonnull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MyNullable public String field2 = null;
|
||||
@MyNullable
|
||||
public String foo2(@MyNonnull String x, CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MyNonnull
|
||||
public String bar2() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.foo2("", null)?.length
|
||||
a.foo2("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar2().length
|
||||
a.bar2()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field2?.length
|
||||
a.field2<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
// JSR305_MIGRATION_REPORT: strict
|
||||
|
||||
// FILE: A.java
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class A {
|
||||
@MyNullable
|
||||
public String foo() { return ""; }
|
||||
|
||||
@MyMigrationNullable
|
||||
public String foo2() { return ""; }
|
||||
|
||||
@Nullable
|
||||
public String foo3() { return ""; }
|
||||
|
||||
public String foo4() { return ""; }
|
||||
|
||||
public void bar(@MyNonnull String baz) { }
|
||||
|
||||
public void bar2(@MyMigrationNonnull String baz) { }
|
||||
|
||||
public void bar3(@Nonnull String baz) {}
|
||||
|
||||
public void bar4(String baz) {}
|
||||
}
|
||||
|
||||
// FILE: B.java
|
||||
public class B extends A {
|
||||
@MyMigrationNullable
|
||||
public String foo() { return ""; }
|
||||
|
||||
@MyNullable
|
||||
public String foo2() { return ""; }
|
||||
|
||||
@MyNullable
|
||||
public String foo3() { return ""; }
|
||||
|
||||
@MyNullable
|
||||
public String foo4() { return ""; }
|
||||
|
||||
public void bar(@MyMigrationNonnull String baz) { }
|
||||
|
||||
public void bar2(@MyNonnull String baz) { }
|
||||
|
||||
public void bar3(@MyNonnull String baz) {}
|
||||
|
||||
public void bar4(@MyNonnull String baz) {}
|
||||
}
|
||||
|
||||
// FILE: C.java
|
||||
public class C extends A {
|
||||
@MyMigrationNullable
|
||||
public String foo4() { return ""; }
|
||||
|
||||
public void bar4(@MyMigrationNonnull String baz) {}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(b: B, c: C) {
|
||||
b.foo()<!UNSAFE_CALL!>.<!>length
|
||||
b.foo()?.length
|
||||
b.foo2()<!UNSAFE_CALL!>.<!>length
|
||||
b.foo2()?.length
|
||||
b.foo3()<!UNSAFE_CALL!>.<!>length
|
||||
b.foo3()?.length
|
||||
b.foo4()<!UNSAFE_CALL!>.<!>length
|
||||
b.foo4()?.length
|
||||
|
||||
b.bar(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
b.bar("")
|
||||
b.bar2(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
b.bar2("")
|
||||
b.bar3(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
b.bar3("")
|
||||
b.bar4(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
b.bar4("")
|
||||
|
||||
c.foo4()<!UNSAFE_CALL!>.<!>length
|
||||
c.foo4()?.length
|
||||
c.bar4(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
c.bar4("")
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: ignore
|
||||
// JSR305_MIGRATION_REPORT: ignore
|
||||
// JSR305_SPECIAL_REPORT: MyNonnull:warn, MyMigrationNonnull:strict
|
||||
|
||||
// FILE: A.java
|
||||
import javax.annotation.*;
|
||||
|
||||
public class A {
|
||||
@MyMigrationNullable public String field = null;
|
||||
|
||||
@MyMigrationNullable
|
||||
public String foo(@MyMigrationNonnull String x, CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MyNonnull
|
||||
@MyMigrationNonnull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: ignore
|
||||
// JSR305_MIGRATION_REPORT: warn
|
||||
// JSR305_SPECIAL_REPORT: MyNonnull:strict
|
||||
|
||||
// FILE: A.java
|
||||
import javax.annotation.*;
|
||||
|
||||
public class A {
|
||||
@MyMigrationNullable public String field = null;
|
||||
|
||||
@MyMigrationNullable
|
||||
public String foo(@MyMigrationNonnull String x, CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MyMigrationNonnull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MyNullable public String field2 = null;
|
||||
@MyNullable
|
||||
public String foo2(@MyNonnull String x, CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@MyNonnull
|
||||
public String bar2() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(a: A) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.foo2("", null)?.length
|
||||
a.foo2("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar2().length
|
||||
a.bar2()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field2?.length
|
||||
a.field2<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// FILE: main.kt
|
||||
sealed class ClientBootResult
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// MUTE_FOR_PSI_CLASS_FILES_READING
|
||||
|
||||
// FILE: J1.java
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
|
||||
// FILE: A.java
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
// NULLABILITY_ANNOTATIONS: @io.reactivex.annotations:strict, @org.eclipse.jdt.annotation:warn, @androidx.annotation:strict, @com.android.annotations:ignore
|
||||
|
||||
// FILE: A1.java
|
||||
import io.reactivex.annotations.*;
|
||||
|
||||
public class A1<T> {
|
||||
@Nullable public String field = null;
|
||||
|
||||
@Nullable
|
||||
public String foo(@NonNull String x, @Nullable CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public T baz(@NonNull T x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: A2.java
|
||||
import org.eclipse.jdt.annotation.*;
|
||||
|
||||
public class A2<T> {
|
||||
@Nullable public String field = null;
|
||||
|
||||
@Nullable
|
||||
public String foo(@NonNull String x, @Nullable CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public T baz(@NonNull T x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: A3.java
|
||||
import androidx.annotation.*;
|
||||
|
||||
public class A3<T> {
|
||||
@Nullable public String field = null;
|
||||
|
||||
@Nullable
|
||||
public String foo(@NonNull String x, @Nullable CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public T baz(@NonNull T x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: A4.java
|
||||
import com.android.annotations.*;
|
||||
|
||||
public class A4<T> {
|
||||
@Nullable public String field = null;
|
||||
|
||||
@Nullable
|
||||
public String foo(@NonNull String x, @Nullable CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public T baz(@NonNull T x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main1(a: A1<String>, a1: A1<String?>) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.baz("")<!UNSAFE_CALL!>.<!>length
|
||||
a.baz("")?.length
|
||||
a.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a1.baz("")!!.length
|
||||
a1.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)!!.length
|
||||
}
|
||||
|
||||
fun main2(a: A2<String>, a1: A2<String?>) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.baz("")<!UNSAFE_CALL!>.<!>length
|
||||
a.baz("")?.length
|
||||
a.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a1.baz("")!!.length
|
||||
a1.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)!!.length
|
||||
}
|
||||
|
||||
fun main3(a: A3<String>, a1: A3<String?>) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.baz("")<!UNSAFE_CALL!>.<!>length
|
||||
a.baz("")?.length
|
||||
a.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a1.baz("")!!.length
|
||||
a1.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)!!.length
|
||||
}
|
||||
|
||||
fun main4(a: A4<String>, a1: A4<String?>) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null).length
|
||||
a.foo(null, "").length
|
||||
|
||||
a.bar().length
|
||||
a.bar()!!.length
|
||||
|
||||
a.field?.length
|
||||
a.field.length
|
||||
|
||||
a.baz("").length
|
||||
a.baz("")?.length
|
||||
a.baz(null).length
|
||||
|
||||
a1.baz("")!!.length
|
||||
a1.baz(null)!!.length
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
|
||||
// FILE: A.java
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// FILE: A.java
|
||||
|
||||
import io.reactivex.rxjava3.annotations.*;
|
||||
|
||||
public class A<T> {
|
||||
@Nullable public String field = null;
|
||||
|
||||
@Nullable
|
||||
public String foo(@NonNull String x, @Nullable CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public T baz(@NonNull T x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
fun main(a: A<String>, a1: A<String?>) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.baz("")<!UNSAFE_CALL!>.<!>length
|
||||
a.baz("")?.length
|
||||
a.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a1.baz("")!!.length
|
||||
a1.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)!!.length
|
||||
}
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// NULLABILITY_ANNOTATIONS: @io.reactivex.rxjava3.annotations:strict
|
||||
|
||||
// FILE: A.java
|
||||
@@ -40,4 +41,4 @@ fun main(a: A<String>, a1: A<String?>) {
|
||||
|
||||
a1.baz("")!!.length
|
||||
a1.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)!!.length
|
||||
}
|
||||
}
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
// NULLABILITY_ANNOTATIONS: @io.reactivex.rxjava3.annotations:ignore
|
||||
|
||||
// FILE: A.java
|
||||
|
||||
import io.reactivex.rxjava3.annotations.*;
|
||||
|
||||
public class A<T> {
|
||||
@Nullable public String field = null;
|
||||
|
||||
@Nullable
|
||||
public String foo(@NonNull String x, @Nullable CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public T baz(@NonNull T x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
fun main(a: A<String>, a1: A<String?>) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.baz("")<!UNSAFE_CALL!>.<!>length
|
||||
a.baz("")?.length
|
||||
a.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a1.baz("")!!.length
|
||||
a1.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)!!.length
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
// NULLABILITY_ANNOTATIONS: @io.reactivex.rxjava3.annotations:warn
|
||||
|
||||
// FILE: A.java
|
||||
|
||||
import io.reactivex.rxjava3.annotations.*;
|
||||
|
||||
public class A<T> {
|
||||
@Nullable public String field = null;
|
||||
|
||||
@Nullable
|
||||
public String foo(@NonNull String x, @Nullable CharSequence y) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String bar() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public T baz(@NonNull T x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
fun main(a: A<String>, a1: A<String?>) {
|
||||
a.foo("", null)?.length
|
||||
a.foo("", null)<!UNSAFE_CALL!>.<!>length
|
||||
a.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.baz("")<!UNSAFE_CALL!>.<!>length
|
||||
a.baz("")?.length
|
||||
a.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a1.baz("")!!.length
|
||||
a1.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)!!.length
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// JSR305_GLOBAL_REPORT: warn
|
||||
|
||||
// FILE: NonNullApi.java
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@MyNonnull
|
||||
@TypeQualifierDefault({ ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD })
|
||||
public @interface NonNullApi {
|
||||
}
|
||||
|
||||
// FILE: MigrationNonNullApi.java
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
import kotlin.annotations.jvm.*;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@MyNonnull
|
||||
@UnderMigration(status = MigrationStatus.STRICT)
|
||||
@TypeQualifierDefault({ ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD })
|
||||
public @interface MigrationNonNullApi {
|
||||
}
|
||||
|
||||
// FILE: PolicyFromDefault.java
|
||||
@NonNullApi
|
||||
public class PolicyFromDefault {
|
||||
public String foo(String x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
public String bar = "bar";
|
||||
}
|
||||
|
||||
// FILE: PolicyFromNickname.java
|
||||
@MigrationNonNullApi
|
||||
public class PolicyFromNickname {
|
||||
public String foo(String x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
public String bar = "bar";
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun main(default: PolicyFromDefault, nickname: PolicyFromNickname) {
|
||||
default.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
default.foo("hello").length
|
||||
|
||||
nickname.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||
nickname.foo("hello").length
|
||||
}
|
||||
Reference in New Issue
Block a user