diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsCompiledJavaTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsCompiledJavaTestGenerated.java index e922370f5a7..cb097a18770 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsCompiledJavaTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsCompiledJavaTestGenerated.java @@ -627,6 +627,12 @@ public class FirOldFrontendForeignAnnotationsCompiledJavaTestGenerated extends A KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("default.kt") + public void testDefault() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.kt"); + } + @Nested @TestMetadata("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated.java index de3dabfd549..b576a256a30 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated.java @@ -627,6 +627,12 @@ public class FirOldFrontendForeignAnnotationsCompiledJavaWithPsiClassReadingTest KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("default.kt") + public void testDefault() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.kt"); + } + @Nested @TestMetadata("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsSourceJavaTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsSourceJavaTestGenerated.java index 3ad0ad75951..b15f02e0757 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsSourceJavaTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendForeignAnnotationsSourceJavaTestGenerated.java @@ -627,6 +627,12 @@ public class FirOldFrontendForeignAnnotationsSourceJavaTestGenerated extends Abs KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("default.kt") + public void testDefault() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.kt"); + } + @Nested @TestMetadata("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/test/util/KtTestUtil.java b/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/test/util/KtTestUtil.java index 6c9fe020f81..f0cce7af447 100644 --- a/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/test/util/KtTestUtil.java +++ b/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/test/util/KtTestUtil.java @@ -124,7 +124,7 @@ public class KtTestUtil { if (otherProp != null) { return getJdkHome(otherProp, null, prop); } else { - throw new AssertionError("Environment variable " + propToReport + " is not set!"); + return getJdkHome("JDK_8", "JDK_18"); } } return new File(jdk); diff --git a/compiler/testData/cli/jvm/jspecifyByLv16.out b/compiler/testData/cli/jvm/jspecifyByLv16.out index 2a911ebf791..7c2a6d77f6e 100644 --- a/compiler/testData/cli/jvm/jspecifyByLv16.out +++ b/compiler/testData/cli/jvm/jspecifyByLv16.out @@ -1,4 +1,7 @@ -compiler/testData/cli/jvm/jspecifyUsage.kt:2:11: error: null can not be a value of a non-null type String +compiler/testData/cli/jvm/jspecifyUsage.kt:2:11: warning: type mismatch: inferred type is Nothing? but String was expected a.foo(null) ^ -COMPILATION_ERROR +compiler/testData/cli/jvm/jspecifyUsage.kt:3:5: warning: unsafe use of a nullable receiver of type String? + a.bar().hashCode() + ^ +OK diff --git a/compiler/testData/cli/jvm/jspecifyDefault.out b/compiler/testData/cli/jvm/jspecifyDefault.out index 2a911ebf791..7c2a6d77f6e 100644 --- a/compiler/testData/cli/jvm/jspecifyDefault.out +++ b/compiler/testData/cli/jvm/jspecifyDefault.out @@ -1,4 +1,7 @@ -compiler/testData/cli/jvm/jspecifyUsage.kt:2:11: error: null can not be a value of a non-null type String +compiler/testData/cli/jvm/jspecifyUsage.kt:2:11: warning: type mismatch: inferred type is Nothing? but String was expected a.foo(null) ^ -COMPILATION_ERROR +compiler/testData/cli/jvm/jspecifyUsage.kt:3:5: warning: unsafe use of a nullable receiver of type String? + a.bar().hashCode() + ^ +OK diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.fir.kt new file mode 100644 index 00000000000..8f7790ca000 --- /dev/null +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.fir.kt @@ -0,0 +1,29 @@ +// FILE: NullnessUnspecifiedTypeParameter.java +import org.jspecify.nullness.*; + +@NullMarked +public class NullnessUnspecifiedTypeParameter { + public void foo(T t) {} + + public void bar(Test s, T t) {} // t should not become not nullable +} + +// FILE: Test.java +public class Test {} + +// FILE: main.kt +fun main(a1: NullnessUnspecifiedTypeParameter, a2: NullnessUnspecifiedTypeParameter, x: Test): Unit { + a1.foo(null) + a1.foo(1) + + a2.foo(null) + a2.foo(1) + + a1.bar(null, null) + a1.bar(x, null) + a1.bar(x, 1) + + a2.bar(null, null) + a2.bar(x, null) + a2.bar(x, 1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.kt new file mode 100644 index 00000000000..11dffc30cbd --- /dev/null +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.kt @@ -0,0 +1,35 @@ +// FILE: NullnessUnspecifiedTypeParameter.java +import org.jspecify.nullness.*; + +@NullMarked +public class NullnessUnspecifiedTypeParameter { + public void foo(T t) {} + + public void bar(Test s, T t) {} // t should not become not nullable +} + +// FILE: Test.java +public class Test {} + +// FILE: main.kt +fun main(a1: NullnessUnspecifiedTypeParameter, a2: NullnessUnspecifiedTypeParameter, x: Test): Unit { + // jspecify_nullness_mismatch + a1.foo(null) + a1.foo(1) + + // jspecify_nullness_mismatch + a2.foo(null) + a2.foo(1) + + // jspecify_nullness_mismatch, jspecify_nullness_mismatch + a1.bar(null, null) + // jspecify_nullness_mismatch + a1.bar(x, null) + a1.bar(x, 1) + + // jspecify_nullness_mismatch, jspecify_nullness_mismatch + a2.bar(null, null) + // jspecify_nullness_mismatch + a2.bar(x, null) + a2.bar(x, 1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.txt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.txt new file mode 100644 index 00000000000..163bebaf51d --- /dev/null +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.txt @@ -0,0 +1,19 @@ +package + +public fun main(/*0*/ a1: NullnessUnspecifiedTypeParameter, /*1*/ a2: NullnessUnspecifiedTypeParameter, /*2*/ x: Test): kotlin.Unit + +@org.jspecify.nullness.NullMarked public open class NullnessUnspecifiedTypeParameter { + public constructor NullnessUnspecifiedTypeParameter() + public open fun bar(/*0*/ s: Test!, /*1*/ t: T!): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open fun foo(/*0*/ t: T!): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public open class Test { + public constructor Test() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} 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 b590d91f189..685fa024920 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 @@ -627,6 +627,12 @@ public class ForeignAnnotationsCompiledJavaTestGenerated extends AbstractForeign KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("default.kt") + public void testDefault() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.kt"); + } + @Nested @TestMetadata("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode") @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 a33834e69ba..232a42da463 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 @@ -627,6 +627,12 @@ public class ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated exte KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("default.kt") + public void testDefault() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.kt"); + } + @Nested @TestMetadata("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode") @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 5ff5ffb51e0..8f007f7291a 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 @@ -627,6 +627,12 @@ public class ForeignAnnotationsSourceJavaTestGenerated extends AbstractForeignAn KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("default.kt") + public void testDefault() throws Exception { + runTest("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/default.kt"); + } + @Nested @TestMetadata("compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode") @TestDataPath("$PROJECT_ROOT") diff --git a/core/compiler.common.jvm/src/org/jetbrains/kotlin/load/java/JavaNullabilityAnnotationSettings.kt b/core/compiler.common.jvm/src/org/jetbrains/kotlin/load/java/JavaNullabilityAnnotationSettings.kt index 5262126964f..c192fc4b9b9 100644 --- a/core/compiler.common.jvm/src/org/jetbrains/kotlin/load/java/JavaNullabilityAnnotationSettings.kt +++ b/core/compiler.common.jvm/src/org/jetbrains/kotlin/load/java/JavaNullabilityAnnotationSettings.kt @@ -36,7 +36,7 @@ val NULLABILITY_ANNOTATION_SETTINGS: NullabilityAnnotationStates