Skip to content
Permalink
Browse files

8243057: compilation of annotated static record fields fails with NPE

Reviewed-by: jlahoda
  • Loading branch information
Vicente Romero committed Jul 24, 2020
1 parent 77c4adb commit 75d642a4679d3a7dbd9e084de4bbd89ce7315955
@@ -2907,10 +2907,9 @@ public void validateTypeAnnotations(List<JCAnnotation> annotations, boolean isTy
*/
private void validateAnnotation(JCAnnotation a, JCTree declarationTree, Symbol s) {
validateAnnotationTree(a);
boolean isRecordMember = (s.flags_field & RECORD) != 0 || s.enclClass() != null && s.enclClass().isRecord();
boolean isRecordMember = ((s.flags_field & RECORD) != 0 || s.enclClass() != null && s.enclClass().isRecord());

boolean isRecordField = isRecordMember &&
(s.flags_field & (Flags.PRIVATE | Flags.FINAL | Flags.GENERATED_MEMBER | Flags.RECORD)) != 0 &&
boolean isRecordField = (s.flags_field & RECORD) != 0 &&
declarationTree.hasTag(VARDEF) &&
s.owner.kind == TYP;

@@ -1563,4 +1563,37 @@ record R(int i) {
"""
);
}

public void testNoNPEStaticAnnotatedFields() {
assertOK(
"""
import java.lang.annotation.Native;
record R() {
@Native public static final int i = 0;
}
"""
);
assertOK(
"""
import java.lang.annotation.Native;
class Outer {
record R() {
@Native public static final int i = 0;
}
}
"""
);
assertOK(
"""
import java.lang.annotation.Native;
class Outer {
void m() {
record R () {
@Native public static final int i = 0;
}
}
}
"""
);
}
}

0 comments on commit 75d642a

Please sign in to comment.