[java-inspections] ReflectionForUnavailableAnnotation: fix NullPointerException

GitOrigin-RevId: 203ff77a14096913a4b9c8b07ee4eea9ea658cf6
This commit is contained in:
Andrey.Cherkasov
2021-10-18 10:46:12 +03:00
committed by intellij-monorepo-bot
parent 25b1f21fb7
commit 06369b2c81
3 changed files with 26 additions and 2 deletions

View File

@@ -0,0 +1,10 @@
// "Annotate annotation 'NotNull' as @Retention" "false"
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Method;
class Foo {
boolean bar(Method method) {
return method.getAnnotation(NotNull.class<caret>) != null;
}
}

View File

@@ -0,0 +1,10 @@
// "Annotate annotation 'Subst' as @Retention" "false"
import org.intellij.lang.annotations.Subst;
import java.lang.reflect.Method;
class Foo {
boolean bar(Method method) {
return method.getAnnotation(Subst.class<caret>) != null;
}
}

View File

@@ -98,8 +98,12 @@ public class ReflectionForUnavailableAnnotationInspection extends BaseInspection
return;
}
final PsiAnnotation retentionAnnotation = modifierList.findAnnotation(CommonClassNames.JAVA_LANG_ANNOTATION_RETENTION);
if (retentionAnnotation == null && annotationClass.isWritable()) {
registerError(arg, annotationClass);
if (retentionAnnotation == null) {
if (annotationClass.isWritable()) {
registerError(arg, annotationClass);
} else {
registerError(arg);
}
return;
}
final PsiAnnotationParameterList parameters = retentionAnnotation.getParameterList();