Skip to content

Commit ec6376c

Browse files
NPE because annotation.resolvedType is null (#4621)
* Fixes #4616
1 parent d4016be commit ec6376c

File tree

2 files changed

+370
-5
lines changed

2 files changed

+370
-5
lines changed

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -944,11 +944,6 @@ private VariableBinding resolveTypeFor(VariableBinding variable) {
944944
if ((variable.modifiers & ExtraCompilerModifiers.AccUnresolved) == 0)
945945
return variable;
946946

947-
if ((variable.getAnnotationTagBits() & TagBits.AnnotationDeprecated) != 0)
948-
variable.modifiers |= ClassFileConstants.AccDeprecated;
949-
if (hasRestrictedAccess())
950-
variable.modifiers |= ExtraCompilerModifiers.AccRestrictedAccess;
951-
952947
MethodScope initializationScope = variable.isStatic()
953948
? this.scope.referenceContext.staticInitializerScope
954949
: this.scope.referenceContext.initializerScope;
@@ -957,6 +952,7 @@ private VariableBinding resolveTypeFor(VariableBinding variable) {
957952
if (variable instanceof FieldBinding field)
958953
initializationScope.initializedField = field;
959954
AbstractVariableDeclaration variableDeclaration = variable instanceof FieldBinding field ? field.sourceField() : ((RecordComponentBinding) variable).sourceRecordComponent();
955+
ASTNode.resolveNullDefaultAnnotations(initializationScope, variableDeclaration.annotations, variable);
960956
TypeBinding variableType =
961957
variableDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT
962958
? initializationScope.environment().convertToRawType(this, false /*do not force conversion of enclosing types*/) // enum constant is implicitly of declaring enum type
@@ -985,6 +981,11 @@ private VariableBinding resolveTypeFor(VariableBinding variable) {
985981
variable.modifiers |= ExtraCompilerModifiers.AccGenericSignature;
986982
}
987983

984+
if ((variable.getAnnotationTagBits() & TagBits.AnnotationDeprecated) != 0)
985+
variable.modifiers |= ClassFileConstants.AccDeprecated;
986+
if (hasRestrictedAccess())
987+
variable.modifiers |= ExtraCompilerModifiers.AccRestrictedAccess;
988+
988989
Annotation [] annotations = variableDeclaration.annotations;
989990

990991
if (variableDeclaration instanceof RecordComponent componentDeclaration) {

0 commit comments

Comments
 (0)