[FIR] Implement warnings for java nullability type mismatch

#KT-56989
This commit is contained in:
Kirill Rakhman
2023-09-20 15:34:48 +02:00
committed by Space Team
parent 1ecbc094ec
commit a6fdeeb7df
158 changed files with 741 additions and 2021 deletions
@@ -26,21 +26,21 @@ public class A<T> {
// FILE: main.kt
fun main(a: A<String>, a1: A<String?>) {
a.foo("", null)?.length
a.foo("", null).length
a.foo(null, "").length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo("", null)<!>.length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "")<!>.length
a.bar().length
a.bar()!!.length
a.field?.length
a.field.length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.field<!>.length
a.baz("").length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz("")<!>.length
a.baz("")?.length
a.baz(null).length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>)<!>.length
a1.baz("")!!.length
a1.baz(null)!!.length
a1.baz(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>)!!.length
a.baz2("").length
a.baz2("")?.length
@@ -18,7 +18,7 @@ public class ClassWithExternalAnnotatedMembers {
// FILE: usage.kt
fun test() {
val i: Int? = null
ClassWithExternalAnnotatedMembers(i)
ClassWithExternalAnnotatedMembers(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>i<!>)
val s: String? = null
<!NONE_APPLICABLE!>ClassWithExternalAnnotatedMembers<!>(s)
@@ -14,7 +14,7 @@ public class ClassWithExternalAnnotatedMembers {
// FILE: usage.kt
fun test() {
val i: Int? = null
ClassWithExternalAnnotatedMembers(i)
ClassWithExternalAnnotatedMembers(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>i<!>)
val s: String? = null
<!NONE_APPLICABLE!>ClassWithExternalAnnotatedMembers<!>(s)
@@ -22,7 +22,7 @@ fun test() {
val b: Boolean? = null
<!NONE_APPLICABLE!>ClassWithExternalAnnotatedMembers<!>(b)
ClassWithExternalAnnotatedMembers(null)
ClassWithExternalAnnotatedMembers(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>)
}
// FILE: annotations.xml
@@ -16,12 +16,12 @@ fun test() {
instance.<!NONE_APPLICABLE!>method<!>(i)
val s: String? = null
instance.method(s)
instance.method(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>s<!>)
val b: Boolean? = null
instance.<!NONE_APPLICABLE!>method<!>(b)
instance.method(null)
instance.method(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>)
}
// FILE: annotations.xml
@@ -19,7 +19,7 @@ fun test() {
instance.<!NONE_APPLICABLE!>method<!>(i)
val s: String? = null
instance.method(s)
instance.method(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>s<!>)
val b: Boolean? = null
instance.method(b)
@@ -0,0 +1,15 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: warn
// FILE: A.java
public class A {
public static @MyNullable String bar() {
return null;
}
}
// FILE: main.kt
fun foo1(): String = <!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>A.bar()<!>
fun foo2(): String? = A.bar()
fun foo3() = A.bar()
@@ -10,40 +10,40 @@ public class J {
}
// FILE: k.kt
fun test() {
var platformNN = J.staticNN
var platformN = J.staticN
var platformJ = J.staticJ
var platformNN = J.staticNN
var platformN = J.staticN
var platformJ = J.staticJ
fun test() {
+platformNN
+platformN
+<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>
+platformJ
++platformNN
++platformN
++<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>
++platformJ
platformNN++
platformN++
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN++<!>
platformJ++
1 + platformNN
1 + platformN
1 + <!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>
1 + platformJ
platformNN + 1
platformN + 1
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!> + 1
platformJ + 1
1 <!INFIX_MODIFIER_REQUIRED!>plus<!> platformNN
1 <!INFIX_MODIFIER_REQUIRED!>plus<!> platformN
1 <!INFIX_MODIFIER_REQUIRED!>plus<!> <!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>
1 <!INFIX_MODIFIER_REQUIRED!>plus<!> platformJ
platformNN <!INFIX_MODIFIER_REQUIRED!>plus<!> 1
platformN <!INFIX_MODIFIER_REQUIRED!>plus<!> 1
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!> <!INFIX_MODIFIER_REQUIRED!>plus<!> 1
platformJ <!INFIX_MODIFIER_REQUIRED!>plus<!> 1
platformNN += 1
platformN += 1
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!> += 1
platformJ += 1
}
@@ -10,11 +10,11 @@ public class J {
}
// FILE: k.kt
fun test() {
var platformNN = J.staticNN
var platformN = J.staticN
var platformJ = J.staticJ
var platformNN = J.staticNN
var platformN = J.staticN
var platformJ = J.staticJ
fun test() {
+platformNN
+<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>
+platformJ
@@ -1,5 +1,8 @@
package
public var platformJ: kotlin.Int!
public var platformN: kotlin.Int!
public var platformNN: kotlin.Int!
public fun test(): kotlin.Unit
public open class J {
@@ -1,25 +0,0 @@
// 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]
platformN[0]
platformJ[0]
platformNN[0] = 1
platformN[0] = 1
platformJ[0] = 1
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// JSR305_GLOBAL_REPORT: warn
// FILE: J.java
@@ -1,24 +0,0 @@
// 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 = J.staticN
v = J.staticJ
n = J.staticNN
n = J.staticN
n = J.staticJ
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// JSR305_GLOBAL_REPORT: warn
// FILE: J.java
@@ -17,26 +17,26 @@ fun test() {
val platformJ = J.staticJ
if (platformNN) {}
if (platformN) {}
if (<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>) {}
if (platformJ) {}
while (platformNN) {}
while (platformN) {}
while (<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>) {}
while (platformJ) {}
do {} while (platformNN)
do {} while (platformN)
do {} while (<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>)
do {} while (platformJ)
platformNN && false
platformN && false
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!> && false
platformJ && false
platformNN || false
platformN || false
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!> || false
platformJ || false
!platformNN
!platformN
!<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>
!platformJ
}
@@ -1,29 +0,0 @@
// !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(n)
J.staticNN = n
if (n != null) {
foo(n)
J.staticNN = n
}
val x: J? = null
J.staticNN = x
if (x != null) {
J.staticNN = x
}
}
fun foo(j: J) {}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: warn
@@ -1,22 +0,0 @@
// !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) {}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: warn
@@ -1,21 +0,0 @@
// 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 J.staticN
var C by J.staticJ
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// JSR305_GLOBAL_REPORT: warn
// FILE: J.java
@@ -17,14 +17,14 @@ fun test() {
val platformJ = J.staticJ
platformNN.foo()
platformN.foo()
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>.foo()
platformJ.foo()
with(platformNN) {
foo()
}
with(platformN) {
foo()
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>foo()<!>
}
with(platformJ) {
foo()
@@ -22,14 +22,14 @@ fun test() {
val platformJ = J.staticJ
platformNN.foo()
platformN.foo()
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>.foo()
platformJ.foo()
with(platformNN) {
foo()
}
with(platformN) {
foo()
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>foo()<!>
}
with(platformJ) {
foo()
@@ -1,26 +0,0 @@
// !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>(platformN)
checkSubtype<J>(platformJ)
checkSubtype<J?>(platformNN)
checkSubtype<J?>(platformN)
checkSubtype<J?>(platformJ)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
// JSR305_GLOBAL_REPORT: warn
@@ -1,23 +0,0 @@
// 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 platformN) {}
for (x in platformJ) {}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// JSR305_GLOBAL_REPORT: warn
// FILE: J.java
@@ -1,4 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// LANGUAGE: +ContextReceivers
// JSR305_GLOBAL_REPORT: warn
// FILE: J.java
@@ -13,13 +14,23 @@ public class J {
// FILE: k.kt
fun test() {
foo(J.staticNN)
foo(J.staticN)
foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>J.staticN<!>)
foo(J.staticJ)
bar(J.staticNN)
bar(J.staticN)
bar(J.staticJ)
with(J.staticNN) { baz() }
with(J.staticN) { <!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>baz()<!> }
with(J.staticJ) { baz() }
with(J.staticNN) { qux() }
with(J.staticN) { qux() }
with(J.staticJ) { qux() }
}
fun foo(j: J) {}
fun bar(j: J?) {}
context(J) fun baz() {}
context(J?) fun qux() {}
@@ -1,4 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// LANGUAGE: +ContextReceivers
// JSR305_GLOBAL_REPORT: warn
// FILE: J.java
@@ -19,7 +20,17 @@ fun test() {
bar(J.staticNN)
bar(J.staticN)
bar(J.staticJ)
with(J.staticNN) { baz() }
with(J.staticN) { baz() }
with(J.staticJ) { baz() }
with(J.staticNN) { qux() }
with(J.staticN) { qux() }
with(J.staticJ) { qux() }
}
fun foo(j: J) {}
fun bar(j: J?) {}
context(J) fun baz() {}
context(J?) fun qux() {}
@@ -1,7 +1,9 @@
package
public fun bar(/*0*/ j: J?): kotlin.Unit
context(J) public fun baz(): kotlin.Unit
public fun foo(/*0*/ j: J): kotlin.Unit
context(J?) public fun qux(): kotlin.Unit
public fun test(): kotlin.Unit
public open class J {
@@ -1,21 +0,0 @@
// 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.staticN()
J.staticJ()
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// JSR305_GLOBAL_REPORT: warn
// FILE: J.java
@@ -1,21 +0,0 @@
// !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].length
}
public fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> {
null!!
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: warn
@@ -22,6 +22,6 @@ fun test() {
val platformJ = J.staticJ
val (a1, b1) = platformNN
val (a2, b2) = platformN
val (<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a2<!>, <!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>b2<!>) = platformN
val (a3, b3) = platformJ
}
@@ -1,88 +0,0 @@
// 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 = n
J.staticNN = 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(n, n, n)
J.staticSet(platformN, platformN, platformN)
J.staticSet(platformJ, platformJ, platformJ)
J().nn = n
J().nn = 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(n, n, n)
J().set(platformN, platformN, platformN)
J().set(platformJ, platformJ, platformJ)
J(nn, nn, nn)
J(platformNN, platformNN, platformNN)
J(n, n, n)
J(platformN, platformN, platformN)
J(platformJ, platformJ, platformJ)
}
@@ -1,3 +1,5 @@
// FIR_IDENTICAL
// WITH_STDLIB
// JSR305_GLOBAL_REPORT: warn
// FILE: J.java
@@ -37,18 +39,39 @@ fun test(n: J?, nn: J) {
J.staticNN = nn
J.staticNN = platformNN
J.staticNN = platformJ
J.staticNN = <!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>
J.staticNN = requireNotNull(J.staticNN)
J.staticNN = requireNotNull(J.staticN)
J.staticNN = requireNotNull(J.staticJ)
J.staticNN = J.staticNN as J
J.staticNN = J.staticN as J
J.staticNN = J.staticJ as J
J.staticN = n
J.staticN = platformN
J.staticN = nn
J.staticN = platformNN
J.staticN = platformJ
J.staticN = null
J.staticN = requireNotNull(J.staticNN)
J.staticN = requireNotNull(J.staticN)
J.staticN = requireNotNull(J.staticJ)
J.staticN = J.staticNN as J
J.staticN = J.staticN as J
J.staticN = J.staticJ as J
J.staticJ = n
J.staticJ = platformN
J.staticJ = nn
J.staticJ = platformNN
J.staticJ = platformJ
J.staticJ = null
J.staticJ = requireNotNull(J.staticNN)
J.staticJ = requireNotNull(J.staticN)
J.staticJ = requireNotNull(J.staticJ)
J.staticJ = J.staticNN as J
J.staticJ = J.staticN as J
J.staticJ = J.staticJ as J
J.staticSet(nn, nn, nn)
J.staticSet(platformNN, platformNN, platformNN)
@@ -1,25 +0,0 @@
// 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]
platformN[0]
platformJ[0]
platformNN[0] = 1
platformN[0] = 1
platformJ[0] = 1
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// JSR305_GLOBAL_REPORT: warn
// FILE: J.java
@@ -1,23 +0,0 @@
// 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
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// JSR305_GLOBAL_REPORT: warn
// FILE: J.java
@@ -1,40 +0,0 @@
// !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(t)
val x: T = a.bam()
val y: T = a.baz<T>()
}
}
fun test() {
val a = A<String?>()
a.foo(null)
val b: String = a.bar()
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: warn
@@ -77,15 +77,15 @@ public class A {
// FILE: main.kt
fun main(a: A) {
a.foo("", null)?.length
a.foo("", null).length
a.foo(null, "").length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo("", null)<!>.length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "")<!>.length
a.baz("", null).length
a.baz(null, "").length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz("", null)<!>.length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "")<!>.length
a.bar().length
a.bar()!!.length
a.field?.length
a.field.length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.field<!>.length
}
@@ -1,57 +0,0 @@
// !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.length
a.field = null
a.nonNullField<!UNNECESSARY_SAFE_CALL!>?.<!>length
a.nonNullField.length
a.nonNullField = <!NULL_FOR_NONNULL_TYPE!>null<!>
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: warn
@@ -126,25 +126,25 @@ public class C extends A implements AInt {
// FILE: main.kt
fun main(a: A, b: B, c: C) {
a.foo1(null).length
a.foo2(null).length
a.foo3(null).length
a.foo1(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>).length
a.foo2(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>).length
a.foo3(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>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).length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>b.foo1(null)<!>.length
b.foo1(null)?.length
b.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
b.foo3(null).length
b.foo3(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>).length
b.bar1(null)<!UNSAFE_CALL!>.<!>length
b.bar2(null)<!UNSAFE_CALL!>.<!>length
b.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>b.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)<!>.length
b.baz(<!NULL_FOR_NONNULL_TYPE!>null<!>)?.length
c.foo1(null).length
c.foo1(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>).length
c.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
c.foo3(null).length
c.foo3(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>).length
c.bar1(null)<!UNSAFE_CALL!>.<!>length
c.bar1(null)?.length
c.bar2(null)<!UNSAFE_CALL!>.<!>length
@@ -128,9 +128,9 @@ public class A {
fun main(a: A, b: A.B, c: A.C) {
a.foo("", null)?.length
a.foo("", null).length
a.foo(null, "").length
a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "").length
a.foobar(null, "").length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foobar(null, "")<!>.length
a.foobar("", <!NULL_FOR_NONNULL_TYPE!>null<!>)?.length
a.bar().length
@@ -145,17 +145,17 @@ fun main(a: A, b: A.B, c: A.C) {
// b
b.foo("", <!NULL_FOR_NONNULL_TYPE!>null<!>)?.length
b.foo("", <!NULL_FOR_NONNULL_TYPE!>null<!>).length
b.foo(null, "").length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>b.foo("", <!NULL_FOR_NONNULL_TYPE!>null<!>)<!>.length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>b.foo(null, "")<!>.length
b.foobar(null, "").length
b.foobar(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "").length
b.foobar("", null)?.length
b.bar().length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>b.bar()<!>.length
b.bar()!!.length
b.field?.length
b.field.length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>b.field<!>.length
b.baz()<!UNSAFE_CALL!>.<!>get(0)
b.baz()!!.get(0).get(0)
@@ -164,16 +164,16 @@ fun main(a: A, b: A.B, c: A.C) {
// c
c.foo("", null)?.length
c.foo("", null).length
c.foo(null, "").length
c.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "").length
c.foobar(null, "").length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>c.foobar(null, "")<!>.length
c.foobar("", null)?.length
c.bar().length
c.bar()!!.length
c.field?.length
c.field.length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>c.field<!>.length
c.baz()<!UNSAFE_CALL!>.<!>get(0)
c.baz()!!.get(0).get(0)
@@ -1,33 +0,0 @@
// !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, <!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,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: warn
@@ -1,68 +0,0 @@
// !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
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: warn
@@ -65,7 +65,7 @@ public class A {
fun main(a: A) {
a.foo("", null)?.length
a.foo("", null).length
a.foo(null, "").length
a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "").length
a.bar().length
a.bar()!!.length
@@ -73,7 +73,7 @@ fun main(a: A) {
a.field?.length
a.field.length
a.baz().get(0)
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz()<!>.get(0)
a.baz()!!.get(0).get(0)
a.baz()!!.get(0)?.get(0)
}
@@ -70,7 +70,7 @@ public class A {
fun main(a: test.A) {
a.foo("", null)?.length
a.foo("", null).length
a.foo(null, "").length
a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "").length
a.bar().length
a.bar()!!.length
@@ -78,7 +78,7 @@ fun main(a: test.A) {
a.field?.length
a.field.length
a.baz().get(0)
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz()<!>.get(0)
a.baz()!!.get(0).get(0)
a.baz()!!.get(0)?.get(0)
}
@@ -1,82 +0,0 @@
// !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)
a.foo3("")
a.foo3(null)
a.foo4("")
a.foo4(null)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: ignore
@@ -45,7 +45,7 @@ fun main(a: A) {
a.foo2("", null)?.length
a.foo2("", null).length
a.foo2(null, "").length
a.foo2(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "").length
a.bar2().length
a.bar2()!!.length
@@ -45,7 +45,7 @@ fun main(a: A) {
a.foo2("", null)?.length
a.foo2("", null)<!UNSAFE_CALL!>.<!>length
a.foo2(null, "")<!UNSAFE_CALL!>.<!>length
a.foo2(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "")<!UNSAFE_CALL!>.<!>length
a.bar2().length
a.bar2()!!.length
@@ -1,76 +0,0 @@
// !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).length
a.foo2(null, "").length
a.bar2().length
a.bar2()!!.length
a.field2?.length
a.field2.length
a.field3?.length
a.field3<!UNSAFE_CALL!>.<!>length
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: warn
// JSR305_MIGRATION_REPORT: strict
@@ -1,55 +0,0 @@
// !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).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.foo2("", null)?.length
a.foo2("", null).length
a.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>, "").length
a.bar2().length
a.bar2()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
a.field2?.length
a.field2.length
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: strict
// JSR305_MIGRATION_REPORT: ignore
@@ -35,7 +35,7 @@ public class A {
fun main(a: A) {
a.foo("", null)?.length
a.foo("", null)<!UNSAFE_CALL!>.<!>length
a.foo(null, "")<!UNSAFE_CALL!>.<!>length
a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "")<!UNSAFE_CALL!>.<!>length
a.bar().length
a.bar()!!.length
@@ -1,85 +0,0 @@
// !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().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)
b.bar4("")
c.foo4()<!UNSAFE_CALL!>.<!>length
c.foo4()?.length
c.bar4(<!NULL_FOR_NONNULL_TYPE!>null<!>)
c.bar4("")
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: warn
// JSR305_MIGRATION_REPORT: strict
@@ -34,14 +34,14 @@ public class A {
// FILE: main.kt
fun main(a: A) {
a.foo("", null)?.length
a.foo("", null).length
a.foo(null, "").length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo("", null)<!>.length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "")<!>.length
a.bar().length
a.bar()!!.length
a.field?.length
a.field.length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.field<!>.length
a.foo2("", null)?.length
a.foo2("", null).length
@@ -102,21 +102,21 @@ fun main1(a: A1<String>, a1: A1<String?>) {
fun main2(a: A2<String>, a1: A2<String?>) {
a.foo("", null)?.length
a.foo("", null).length
a.foo(null, "").length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo("", null)<!>.length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "")<!>.length
a.bar().length
a.bar()!!.length
a.field?.length
a.field.length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.field<!>.length
a.baz("").length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz("")<!>.length
a.baz("")?.length
a.baz(null).length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>)<!>.length
a1.baz("")!!.length
a1.baz(null)!!.length
a1.baz(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>)!!.length
}
fun main3(a: A3<String>, a1: A3<String?>) {
@@ -23,19 +23,20 @@ public class A<T> {
fun main(a: A<String>, a1: A<String?>) {
a.foo("", null)?.length
a.foo("", null).length
a.foo(null, "").length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo("", null)<!>.length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "")<!>.length
a.foo("", null)!!.length
a.bar().length
a.bar()!!.length
a.field?.length
a.field.length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.field<!>.length
a.baz("").length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz("")<!>.length
a.baz("")?.length
a.baz(null).length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>)<!>.length
a1.baz("")!!.length
a1.baz(null)!!.length
a1.baz(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>)!!.length
}
@@ -25,6 +25,7 @@ fun main(a: A<String>, a1: A<String?>) {
a.foo("", null)?.length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo("", null)<!>.length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "")<!>.length
a.foo("", null)!!.length
a.bar().length
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
@@ -25,19 +25,19 @@ public class A<T> {
fun main(a: A<String>, a1: A<String?>) {
a.foo("", null)?.length
a.foo("", null).length
a.foo(null, "").length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo("", null)<!>.length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "")<!>.length
a.bar().length
a.bar()!!.length
a.field?.length
a.field.length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.field<!>.length
a.baz("").length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz("")<!>.length
a.baz("")?.length
a.baz(null).length
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>)<!>.length
a1.baz("")!!.length
a1.baz(null)!!.length
a1.baz(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>)!!.length
}
@@ -1,64 +0,0 @@
// !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).length
default.foo("hello").length
nickname.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>).length
nickname.foo("hello").length
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: warn