mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-inspections] NullableStuffInspectionBase: fix order of type-use/non-type-use annotation processing
IDEA-311124 @Nullable parameters are flagged as "not allowed to take null values" GitOrigin-RevId: b5440501a41f0e8c43a9d87ac60bc281708794d3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6412b5f11d
commit
9f044ceb21
+10
-9
@@ -928,16 +928,17 @@ public class NullableStuffInspectionBase extends AbstractBaseJavaLocalInspection
|
||||
PsiParameter parameter) {
|
||||
if (!REPORT_NULLS_PASSED_TO_NOT_NULL_PARAMETER || !holder.isOnTheFly()) return;
|
||||
|
||||
PsiElement elementToHighlight;
|
||||
if (DfaPsiUtil.getTypeNullability(parameter.getType()) == Nullability.NOT_NULL) {
|
||||
elementToHighlight = parameter.getNameIdentifier();
|
||||
PsiElement elementToHighlight = null;
|
||||
NullabilityAnnotationInfo info = nullableManager.findOwnNullabilityInfo(parameter);
|
||||
if (info != null && !info.isInferred()) {
|
||||
if (info.getNullability() == Nullability.NOT_NULL) {
|
||||
PsiAnnotation notNullAnnotation = info.getAnnotation();
|
||||
boolean physical = PsiTreeUtil.isAncestor(parameter, notNullAnnotation, true);
|
||||
elementToHighlight = physical ? notNullAnnotation : parameter.getNameIdentifier();
|
||||
}
|
||||
}
|
||||
else {
|
||||
NullabilityAnnotationInfo info = nullableManager.findOwnNullabilityInfo(parameter);
|
||||
if (info == null || info.getNullability() != Nullability.NOT_NULL || info.isInferred()) return;
|
||||
PsiAnnotation notNullAnnotation = info.getAnnotation();
|
||||
boolean physical = PsiTreeUtil.isAncestor(parameter, notNullAnnotation, true);
|
||||
elementToHighlight = physical ? notNullAnnotation : parameter.getNameIdentifier();
|
||||
else if (DfaPsiUtil.getTypeNullability(parameter.getType()) == Nullability.NOT_NULL) {
|
||||
elementToHighlight = parameter.getNameIdentifier();
|
||||
}
|
||||
if (elementToHighlight == null || !JavaNullMethodArgumentUtil.hasNullArgument(method, parameterIdx)) return;
|
||||
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@NonNullImpl
|
||||
class BugReproduction {
|
||||
public static void main(String[] args) {
|
||||
doSomething(null);
|
||||
}
|
||||
|
||||
public static void doSomething(@Nullable String string) {
|
||||
System.out.printf("%b%n", string);
|
||||
}
|
||||
}
|
||||
|
||||
@Documented
|
||||
@Inherited
|
||||
@Nonnull
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({
|
||||
ElementType.PACKAGE,
|
||||
ElementType.TYPE,
|
||||
})
|
||||
@TypeQualifierDefault({
|
||||
ElementType.FIELD,
|
||||
ElementType.TYPE_USE,
|
||||
})
|
||||
@interface NonNullImpl {
|
||||
}
|
||||
+6
@@ -145,6 +145,12 @@ public class NullableStuffInspectionTest extends LightJavaCodeInsightFixtureTest
|
||||
DataFlowInspectionTest.addJavaxDefaultNullabilityAnnotations(myFixture);
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNullableCalledWithNullUnderNotNullByDefault() {
|
||||
DataFlowInspectionTest.addJavaxNullabilityAnnotations(myFixture);
|
||||
DataFlowInspectionTest.addJavaxDefaultNullabilityAnnotations(myFixture);
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNullableSiblingOverriding() { doTest(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user