RFR: JDK15-8242529: javac defines type annotations incorrectly for record members (constructor and property accessor)

Paul Sandoz paul.sandoz at oracle.com
Thu Jul 9 16:06:12 UTC 2020

Hi Vicente,

The asserts look regular in all four cases, I think :-) If so we can consolidate the check into a single method, off the top of my head:

  RecordComponent recordComponent = RecordNotPreservingNestedTypeAnnotationsTest.class.getRecordComponents()[0];
  check(recordComponent.getAnnotations(), recordComponent.getAnnotatedType());

  Method accessor = recordComponent.getAccessor();
  check(accessor.getAnnotations(), accessor.getAnnotatedReturnType());

  Constructor<?> constructor = RecordNotPreservingNestedTypeAnnotationsTest.class.getConstructor(Callable.class);
  check(constructor.getParameterAnnotations()[0], constructor.getAnnotatedParameterTypes()[0]);

  Field field = RecordNotPreservingNestedTypeAnnotationsTest.class.getDeclaredField(recordComponent.getName());
  check(field.getAnnotations(), field.getAnnotatedType());

Does that work?


> On Jul 8, 2020, at 7:31 PM, Vicente Romero <vicente.romero at oracle.com> wrote:
> Hi,
> Please review fix for [1] at [2]. Current record implementation is not forward nested type annotations to generated members like in:
> record R(@RegularAnnotation @TypeAnnotation Callable<@TypeAnnotation ?> foo) {}
> This patch is fixing one issue that show up in two different generated record members: 
>     - the accessor corresponding to the record component
>     - the corresponding parameter in the canonical constructor
> The issue is that the current implementation is not able to correctly generate the annotated types for these components when such an annotated type has "inner" type annotations like it is the case of `foo` in the example which has `TypeAnnotation` applied to the wildcard. In the case of the corresponding parameter in the canonical constructor the annotated type was generated correctly but the class file reflected the internal type annotation as applied to a field not to a method parameter. In the case of the accessor the inner annotation was not there at all. The patch is making a copy of the expression defining the type of the record component and placing it that the right place for both generated members.
> Thanks,
> Vicente
> [1] https://bugs.openjdk.java.net/browse/JDK-8242529 <https://bugs.openjdk.java.net/browse/JDK-8242529>
> [2] http://cr.openjdk.java.net/~vromero/8242529/webrev.00/ <http://cr.openjdk.java.net/~vromero/8242529/webrev.00/>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20200709/ec220681/attachment.htm>

More information about the compiler-dev mailing list