[kotlin] J2K: make sure that thrown expression is not-null

KTIJ-29147

GitOrigin-RevId: 5d66e5d781c83589d9e6c176a27da3c56b72cfe8
This commit is contained in:
Alexey Belkov
2024-05-30 19:32:09 +04:00
committed by intellij-monorepo-bot
parent 2230a6b862
commit ff9ec9140f
5 changed files with 25 additions and 1 deletions

View File

@@ -5341,6 +5341,11 @@ public abstract class NewJavaToKotlinConverterSingleFileTestGenerated extends Ab
runTest("../../shared/tests/testData/newJ2k/nullability/synchronized.java");
}
@TestMetadata("throw.java")
public void testThrow() throws Exception {
runTest("../../shared/tests/testData/newJ2k/nullability/throw.java");
}
@TestMetadata("VariableAssignedWithNull.java")
public void testVariableAssignedWithNull() throws Exception {
runTest("../../shared/tests/testData/newJ2k/nullability/VariableAssignedWithNull.java");

View File

@@ -5341,6 +5341,11 @@ public abstract class K2JavaToKotlinConverterSingleFileTestGenerated extends Abs
runTest("../../shared/tests/testData/newJ2k/nullability/synchronized.java");
}
@TestMetadata("throw.java")
public void testThrow() throws Exception {
runTest("../../shared/tests/testData/newJ2k/nullability/throw.java");
}
@TestMetadata("VariableAssignedWithNull.java")
public void testVariableAssignedWithNull() throws Exception {
runTest("../../shared/tests/testData/newJ2k/nullability/VariableAssignedWithNull.java");

View File

@@ -426,7 +426,10 @@ class J2KNullityInferrer {
private boolean processParameter(@NotNull PsiParameter parameter, @NotNull PsiReferenceExpression expr, PsiElement parent) {
if (PsiUtil.isAccessedForWriting(expr)) return true;
if (parent instanceof PsiSynchronizedStatement) {
if (parent instanceof PsiThrowStatement) {
registerNotNullAnnotation(parameter);
return true;
} else if (parent instanceof PsiSynchronizedStatement) {
registerNotNullAnnotation(parameter);
return true;
} else if (parent instanceof PsiArrayAccessExpression) {

View File

@@ -0,0 +1,5 @@
public class J {
void foo(Exception notNull) throws Exception {
throw notNull;
}
}

View File

@@ -0,0 +1,6 @@
class J {
@Throws(Exception::class)
fun foo(notNull: Exception) {
throw notNull
}
}