mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-04 17:20:55 +07:00
[java-analysis] IDEA-375799 Container nullability annotation on the method has no effect on method return type
(cherry picked from commit f7cead47f32b2befeabe116a6c2df87682cb1cd2) IJ-CR-169010 GitOrigin-RevId: 036988a6259830532f2174c60c39996d71efe819
This commit is contained in:
committed by
intellij-monorepo-bot
parent
830a094ed8
commit
a0fec72e48
@@ -350,7 +350,7 @@ public abstract class NullableNotNullManager {
|
|||||||
|
|
||||||
private @Nullable NullabilityAnnotationInfo findNullabilityDefault(@NotNull PsiElement place,
|
private @Nullable NullabilityAnnotationInfo findNullabilityDefault(@NotNull PsiElement place,
|
||||||
@NotNull PsiAnnotation.TargetType @NotNull ... placeTargetTypes) {
|
@NotNull PsiAnnotation.TargetType @NotNull ... placeTargetTypes) {
|
||||||
PsiElement element = place.getContext();
|
PsiElement element = place;
|
||||||
while (element != null) {
|
while (element != null) {
|
||||||
if (element instanceof PsiModifierListOwner) {
|
if (element instanceof PsiModifierListOwner) {
|
||||||
NullabilityAnnotationInfo result = getNullityDefault((PsiModifierListOwner)element, placeTargetTypes).forContext(place);
|
NullabilityAnnotationInfo result = getNullityDefault((PsiModifierListOwner)element, placeTargetTypes).forContext(place);
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import org.jspecify.annotations.NullMarked;
|
||||||
|
import org.jspecify.annotations.NullUnmarked;
|
||||||
|
import org.jspecify.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@NullMarked
|
||||||
|
class Container<T extends @Nullable Object> {
|
||||||
|
|
||||||
|
@NullUnmarked
|
||||||
|
List<T> get() {
|
||||||
|
return <warning descr="'null' is returned by the method which is not declared as @Nullable">null</warning>;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -221,5 +221,11 @@ public class DataFlowInspection21Test extends DataFlowInspectionTestCase {
|
|||||||
addJSpecifyNullMarked(myFixture);
|
addJSpecifyNullMarked(myFixture);
|
||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testJSpecifyNullUnmarkedOverNullMarked() {
|
||||||
|
addJSpecifyNullMarked(myFixture);
|
||||||
|
setupTypeUseAnnotations("org.jspecify.annotations", myFixture);
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -63,9 +63,16 @@ public abstract class DataFlowInspectionTestCase extends LightJavaCodeInsightFix
|
|||||||
"""
|
"""
|
||||||
package org.jspecify.annotations;
|
package org.jspecify.annotations;
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
@Target({ElementType.TYPE, ElementType.MODULE})
|
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.MODULE})
|
||||||
public @interface NullMarked {}""";
|
public @interface NullMarked {}""";
|
||||||
fixture.addClass(nullMarked);
|
fixture.addClass(nullMarked);
|
||||||
|
@Language("JAVA") String nullUnmarked =
|
||||||
|
"""
|
||||||
|
package org.jspecify.annotations;
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.MODULE})
|
||||||
|
public @interface NullUnmarked {}""";
|
||||||
|
fixture.addClass(nullUnmarked);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setupTypeUseAnnotations(String pkg, JavaCodeInsightTestFixture fixture) {
|
public static void setupTypeUseAnnotations(String pkg, JavaCodeInsightTestFixture fixture) {
|
||||||
|
|||||||
Reference in New Issue
Block a user