Summary
Ensure that type annotations present in the declaration of record components of a record class are emitted properly into the components of the Record attribute in the class file regardless of whether the record component is annotated with at least one annotation in the declaration annotation location (aka Java SE5 annotation location)
Problem
Presently, javac compiler drops type annotations present in the declaration of record components of a record class, IF the record component declaration DOES NOT ALSO happen to carry SOME annotation in the declaration annotation location. This is because the code location which propagates the annotations is reached only when there is at least SOME annotation present in the declaration annotation location for that record component.
Solution
The fix is to handle the propagation of annotations in a different spot in javac code, which would be reached regardless of whether a record component declaration carries some annotation in declaration annotation location.
(See https://github.com/openjdk/jdk/pull/10741/ for PR)
Specification
Relevant portion of specification javac fails to implement as of now (under a specific situation of the record component not also having an annotation in the declaration annotation location) and which is fixed by the proposed patch is:
JVMS:
4.7.20 The RuntimeVisibleTypeAnnotations Attribute
The RuntimeVisibleTypeAnnotations attribute is an variable-length attribute
in the attributes table of a ClassFile , field_info , method_info , or
record_component_info structure, or Code attribute (§4.1, §4.5, §4.6, §4.7.30,
§4.7.3). The RuntimeVisibleTypeAnnotations attribute stores run-time visible
annotations on types used in the declaration of the corresponding class, field,
method, or record component, or in an expression in the corresponding method
body.
and
4.7.21 The RuntimeInvisibleTypeAnnotations Attribute
The RuntimeInvisibleTypeAnnotations attribute is an variable-length attribute
in the attributes table of a ClassFile , field_info , method_info , or
record_component_info structure, or Code attribute (§4.1, §4.5, §4.6, §4.7.30,
§4.7.3). The RuntimeInvisibleTypeAnnotations attribute stores run-time
invisible annotations on types used in the corresponding declaration of a class, field,
method, or record component, or in an expression in the corresponding method
body
- csr of
-
JDK-8292159 TYPE_USE annotations on generic type arguments of record components discarded
-
- Resolved
-