[java] infer nullity: do not suggest to annotate catch parameters (IDEA-193905)

GitOrigin-RevId: 62db2fd552762a0d2d8dc6a2593782eee78f65c0
This commit is contained in:
Anna Kozlova
2021-10-06 19:14:50 +00:00
committed by intellij-monorepo-bot
parent 4315acc3b8
commit d2fe7d2953
4 changed files with 33 additions and 17 deletions
@@ -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<PsiReference> references = ReferencesSearch.search(variable);
@@ -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;
}
}
}
@@ -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;
}
}
}
@@ -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 {