[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
@@ -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)
}