[FIR] Implement UNNECESSARY_NOT_NULL_ASSERTION checker for java warning level types

This commit is contained in:
Kirill Rakhman
2024-01-03 10:39:59 +01:00
committed by Space Team
parent d6bd31b313
commit 7fb5cbd1f8
24 changed files with 52 additions and 823 deletions
@@ -1,55 +0,0 @@
// !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).length
a.foo2(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "").length
a.bar2().length
a.bar2()!!.length
a.field2?.length
a.field2.length
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: ignore
// JSR305_MIGRATION_REPORT: strict
@@ -1,55 +0,0 @@
// !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).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)<!UNSAFE_CALL!>.<!>length
a.foo2(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "")<!UNSAFE_CALL!>.<!>length
a.bar2().length
a.bar2()!!.length
a.field2?.length
a.field2<!UNSAFE_CALL!>.<!>length
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// JSR305_GLOBAL_REPORT: warn
// JSR305_MIGRATION_REPORT: ignore
@@ -1,55 +0,0 @@
// !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(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "")<!UNSAFE_CALL!>.<!>length
a.bar().length
a.bar()!!.length
a.field?.length
a.field<!UNSAFE_CALL!>.<!>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: warn
@@ -1,55 +0,0 @@
// !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
<!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
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>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: ignore
// JSR305_MIGRATION_REPORT: warn