diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Default.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Default.kt new file mode 100644 index 00000000000..8e3ffb12fc5 --- /dev/null +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Default.kt @@ -0,0 +1,41 @@ +// FILE: A.java + +import io.reactivex.rxjava3.annotations.*; + +public class A { + @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, a1: 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("").length + a.baz("")?.length + a.baz(null).length + + a1.baz("")!!.length + a1.baz(null)!!.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Errors.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Errors.kt new file mode 100644 index 00000000000..62e1733a9e7 --- /dev/null +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Errors.kt @@ -0,0 +1,43 @@ +// NULLABILITY_ANNOTATIONS: @io.reactivex.rxjava3.annotations:strict + +// FILE: A.java + +import io.reactivex.rxjava3.annotations.*; + +public class A { + @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, a1: 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("").length + a.baz("")?.length + a.baz(null).length + + a1.baz("")!!.length + a1.baz(null)!!.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Ignore.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Ignore.kt new file mode 100644 index 00000000000..63fd719279a --- /dev/null +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Ignore.kt @@ -0,0 +1,43 @@ +// NULLABILITY_ANNOTATIONS: @io.reactivex.rxjava3.annotations:ignore + +// FILE: A.java + +import io.reactivex.rxjava3.annotations.*; + +public class A { + @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, a1: 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("").length + a.baz("")?.length + a.baz(null).length + + a1.baz("")!!.length + a1.baz(null)!!.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Warnings.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Warnings.kt new file mode 100644 index 00000000000..7f92dcee9f4 --- /dev/null +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Warnings.kt @@ -0,0 +1,43 @@ +// NULLABILITY_ANNOTATIONS: @io.reactivex.rxjava3.annotations:warn + +// FILE: A.java + +import io.reactivex.rxjava3.annotations.*; + +public class A { + @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, a1: 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("").length + a.baz("")?.length + a.baz(null).length + + a1.baz("")!!.length + a1.baz(null)!!.length +} \ No newline at end of file diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsCompiledJavaTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsCompiledJavaTestGenerated.java index d41bceadb27..068796ec6d5 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsCompiledJavaTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsCompiledJavaTestGenerated.java @@ -98,6 +98,30 @@ public class ForeignAnnotationsCompiledJavaTestGenerated extends AbstractForeign runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava.kt"); } + @Test + @TestMetadata("rxjava3Default.kt") + public void testRxjava3Default() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Default.kt"); + } + + @Test + @TestMetadata("rxjava3Errors.kt") + public void testRxjava3Errors() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Errors.kt"); + } + + @Test + @TestMetadata("rxjava3Ignore.kt") + public void testRxjava3Ignore() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Ignore.kt"); + } + + @Test + @TestMetadata("rxjava3Warnings.kt") + public void testRxjava3Warnings() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Warnings.kt"); + } + @Nested @TestMetadata("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated.java index b1a49b0b39d..6e717b22cc2 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated.java @@ -98,6 +98,30 @@ public class ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated exte runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava.kt"); } + @Test + @TestMetadata("rxjava3Default.kt") + public void testRxjava3Default() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Default.kt"); + } + + @Test + @TestMetadata("rxjava3Errors.kt") + public void testRxjava3Errors() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Errors.kt"); + } + + @Test + @TestMetadata("rxjava3Ignore.kt") + public void testRxjava3Ignore() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Ignore.kt"); + } + + @Test + @TestMetadata("rxjava3Warnings.kt") + public void testRxjava3Warnings() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Warnings.kt"); + } + @Nested @TestMetadata("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsSourceJavaTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsSourceJavaTestGenerated.java index ebb07343737..c65c5f6169b 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsSourceJavaTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ForeignAnnotationsSourceJavaTestGenerated.java @@ -98,6 +98,30 @@ public class ForeignAnnotationsSourceJavaTestGenerated extends AbstractForeignAn runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava.kt"); } + @Test + @TestMetadata("rxjava3Default.kt") + public void testRxjava3Default() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Default.kt"); + } + + @Test + @TestMetadata("rxjava3Errors.kt") + public void testRxjava3Errors() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Errors.kt"); + } + + @Test + @TestMetadata("rxjava3Ignore.kt") + public void testRxjava3Ignore() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Ignore.kt"); + } + + @Test + @TestMetadata("rxjava3Warnings.kt") + public void testRxjava3Warnings() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/rxjava3Warnings.kt"); + } + @Nested @TestMetadata("compiler/testData/diagnostics/foreignAnnotationsTests/tests/jsr305") @TestDataPath("$PROJECT_ROOT") diff --git a/core/compiler.common.jvm/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.kt b/core/compiler.common.jvm/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.kt index d7e2296150f..f5ed6617586 100644 --- a/core/compiler.common.jvm/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.kt +++ b/core/compiler.common.jvm/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.kt @@ -35,7 +35,8 @@ val NULLABLE_ANNOTATIONS = listOf( FqName("edu.umd.cs.findbugs.annotations.CheckForNull"), FqName("edu.umd.cs.findbugs.annotations.Nullable"), FqName("edu.umd.cs.findbugs.annotations.PossiblyNull"), - FqName("io.reactivex.annotations.Nullable") + FqName("io.reactivex.annotations.Nullable"), + FqName("io.reactivex.rxjava3.annotations.Nullable") ) val JAVAX_NONNULL_ANNOTATION = FqName("javax.annotation.Nonnull") @@ -51,7 +52,8 @@ val NOT_NULL_ANNOTATIONS = listOf( FqName("org.eclipse.jdt.annotation.NonNull"), FqName("org.checkerframework.checker.nullness.qual.NonNull"), FqName("lombok.NonNull"), - FqName("io.reactivex.annotations.NonNull") + FqName("io.reactivex.annotations.NonNull"), + FqName("io.reactivex.rxjava3.annotations.NonNull") ) val COMPATQUAL_NULLABLE_ANNOTATION = FqName("org.checkerframework.checker.nullness.compatqual.NullableDecl") diff --git a/core/util.runtime/src/org/jetbrains/kotlin/load/java/JavaNullabilityAnnotationSettings.kt b/core/util.runtime/src/org/jetbrains/kotlin/load/java/JavaNullabilityAnnotationSettings.kt index a73baf04f99..5001431ec4d 100644 --- a/core/util.runtime/src/org/jetbrains/kotlin/load/java/JavaNullabilityAnnotationSettings.kt +++ b/core/util.runtime/src/org/jetbrains/kotlin/load/java/JavaNullabilityAnnotationSettings.kt @@ -37,6 +37,11 @@ val nullabilityAnnotationSettings = mapOf( sinceVersion = KotlinVersion(1, 6), reportLevelAfter = ReportLevel.STRICT ), + FqName("io.reactivex.rxjava3.annotations") to JavaNullabilityAnnotationsStatus( + reportLevelBefore = ReportLevel.WARN, + sinceVersion = KotlinVersion(1, 7), + reportLevelAfter = ReportLevel.STRICT + ), ) private val jsr305Settings = JavaNullabilityAnnotationsStatus( diff --git a/third-party/annotations/io/reactivex/rxjava3/annotations/NonNull.java b/third-party/annotations/io/reactivex/rxjava3/annotations/NonNull.java new file mode 100644 index 00000000000..2a65157c940 --- /dev/null +++ b/third-party/annotations/io/reactivex/rxjava3/annotations/NonNull.java @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package io.reactivex.rxjava3.annotations; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.CLASS; + +import java.lang.annotation.*; + +/** + * Indicates that a field/parameter/variable/type parameter/return type is never null. + */ +@Documented +@Target(value = {FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_PARAMETER, TYPE_USE}) +@Retention(value = CLASS) +public @interface NonNull { } diff --git a/third-party/annotations/io/reactivex/rxjava3/annotations/Nullable.java b/third-party/annotations/io/reactivex/rxjava3/annotations/Nullable.java new file mode 100644 index 00000000000..95bac0b80dc --- /dev/null +++ b/third-party/annotations/io/reactivex/rxjava3/annotations/Nullable.java @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package io.reactivex.rxjava3.annotations; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.CLASS; + +import java.lang.annotation.*; + +/** + * Indicates that a field/parameter/variable/type parameter/return type may be null. + */ +@Documented +@Target(value = {FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE_PARAMETER, TYPE_USE}) +@Retention(value = CLASS) +public @interface Nullable { }