diff --git a/java/java-impl/src/com/intellij/codeInspection/inferNullity/NullityInferrer.java b/java/java-impl/src/com/intellij/codeInspection/inferNullity/NullityInferrer.java index da9ae4930d9f..e432f04bf6c9 100644 --- a/java/java-impl/src/com/intellij/codeInspection/inferNullity/NullityInferrer.java +++ b/java/java-impl/src/com/intellij/codeInspection/inferNullity/NullityInferrer.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInspection.inferNullity; import com.intellij.codeInsight.Nullability; @@ -74,7 +74,7 @@ public class NullityInferrer { return false; } } - else if (!variable.hasModifierProperty(PsiModifier.FINAL)) { + else if (!variable.hasModifierProperty(PsiModifier.FINAL) || variable instanceof PsiParameter && ((PsiParameter)variable).getDeclarationScope() instanceof PsiCatchSection) { return false; } final Query references = ReferencesSearch.search(variable); diff --git a/java/java-tests/testData/codeInsight/nullityinferrer/afterCatchParams.java b/java/java-tests/testData/codeInsight/nullityinferrer/afterCatchParams.java new file mode 100644 index 000000000000..697426d6d708 --- /dev/null +++ b/java/java-tests/testData/codeInsight/nullityinferrer/afterCatchParams.java @@ -0,0 +1,13 @@ +import org.jetbrains.annotations.*; + +public class Infer { + static public boolean a(@NotNull String s) { + try { + return s.length() > 0; + } catch (final NullPointerException e) { + e.printStackTrace(); + return false; + } + } + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/nullityinferrer/beforeCatchParams.java b/java/java-tests/testData/codeInsight/nullityinferrer/beforeCatchParams.java new file mode 100644 index 000000000000..8437d507f8dc --- /dev/null +++ b/java/java-tests/testData/codeInsight/nullityinferrer/beforeCatchParams.java @@ -0,0 +1,13 @@ +import org.jetbrains.annotations.*; + +public class Infer { + static public boolean a(String s) { + try { + return s.length() > 0; + } catch (final NullPointerException e) { + e.printStackTrace(); + return false; + } + } + +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/NullityInferrerTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/NullityInferrerTest.java index 0118752e591b..937a90e7d751 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/NullityInferrerTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/NullityInferrerTest.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * 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. - */ +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.java.codeInsight; import com.intellij.JavaTestUtil; @@ -94,6 +80,10 @@ public class NullityInferrerTest extends LightJavaCodeInsightTestCase { public void testTryEnumSwitch() throws Exception { doTest(true); } + + public void testCatchParams() throws Exception { + doTest(true); + } //-----------------------fields--------------------------------------------------- public void testFieldsAssignment() throws Exception {