This commit is contained in:
Coleen Phillimore 2020-07-24 10:51:38 -04:00
commit e6875c9bac
2 changed files with 35 additions and 3 deletions

View File

@ -2907,10 +2907,9 @@ public class Check {
*/
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;

View File

@ -1563,4 +1563,37 @@ public class RecordCompilationTests extends CompilationTestCase {
"""
);
}
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;
}
}
}
"""
);
}
}