[java-dfa] Support annotation nicknames in getAnnotationNullability()

Fixes IDEA-372080 Invalid null check for array with @Nullable
Also: do not attempt to fill nicknames in dumb mode

GitOrigin-RevId: 7955160a958d9891d382ef2736d4c72fe926dbbf
This commit is contained in:
Tagir Valeev
2025-05-15 16:11:33 +00:00
committed by intellij-monorepo-bot
parent 45b2d9b242
commit 74800bc0b5
4 changed files with 91 additions and 38 deletions
@@ -0,0 +1,42 @@
import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierDefault;
import javax.annotation.meta.TypeQualifierNickname;
import javax.annotation.meta.When;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Nonnull(when = When.ALWAYS)
@TypeQualifierNickname
@Target({ElementType.TYPE})
@TypeQualifierDefault({
ElementType.METHOD,
ElementType.FIELD,
ElementType.PARAMETER,
ElementType.LOCAL_VARIABLE,
ElementType.TYPE_PARAMETER,
ElementType.TYPE_USE,
})
@interface DefaultNonNull {
}
@Nonnull(when = When.MAYBE)
@TypeQualifierNickname
@Target({
ElementType.METHOD,
ElementType.FIELD,
ElementType.PARAMETER,
ElementType.LOCAL_VARIABLE,
ElementType.TYPE_USE,
})
@interface Nullable {
}
@DefaultNonNull
class Test {
void test(String s) {
if (<warning descr="Condition 's == null' is always 'false'">s == null</warning>) {}
@Nullable String @Nullable [] arr = new String[] {"a", "b", "c", <warning descr="'null' is stored to an array of @NotNull elements">null</warning>};
@Nullable String @Nullable [] arr2 = {"a", "b", "c", null};
@Nullable String @Nullable [] arr3 = new @Nullable String [] {"a", "b", "c", null};
}
}