RFR: JDK-8198945: Invalid RuntimeVisibleTypeAnnotations for annotation on anonymous class type parameter

Alex Buckley alex.buckley at oracle.com
Fri Jun 29 23:39:17 UTC 2018


On 6/29/2018 3:55 PM, Liam Miller-Cushon wrote:
> The handling of @TB in particular is clearly incorrect:
>
> * @TB appears with a `NEW` type path that leads to the top-level type of
> the 'new' expression, even though @TB appeared on a type argument of
> that type and not at the top level.
>
> * @TB also appears on 'f' with a `CLASS_EXTENDS` path and no bytecode
> offset, which does not provide enough information to associate it with
> the annotated location.

I agree with both points. It is egregious that the method_info structure 
for `f` (as opposed to the Code attribute therein) as a 
Runtime*TypeAnnotations attribute.

> The handling of @TA is also questionable. It makes some sense to use the
> same type path for an annotation on the type of an anonymous class
> declaration as the type of a regular 'new' expression. However that
> results in the same use of @TA appearing twice in bytecode, and
> conflates the type of the anonymous class with its supertype.
>
> I think it is more correct to only emit @TA as a `CLASS_EXTENDS`
> annotation on Test$1, and not include a copy of it at the enclosing method.

I did some digging and found three threads from 2013:

1. "Annotations on anonymous classes"
http://mail.openjdk.java.net/pipermail/type-annotations-spec-experts/2013-February/000063.html

2. "Desugaring of anonymous classes"
http://mail.openjdk.java.net/pipermail/type-annotations-spec-experts/2013-April/000092.html

3. "Desugaring of anonymous classes" (followup)
http://mail.openjdk.java.net/pipermail/type-annotations-spec-experts/2013-August/000127.html

It seems like I changed my mind on the matter of recording @TA:

- In February I agreed with your view, Liam, that @TA should appear only 
as a CLASS_EXTENDS path in the implicit class declaration (Test$1), and 
not as a NEW path in the code of `f`.

- But in April, I said that @TA should be recorded as both paths. Per 
the followup mail in August, this was driven by a longstanding policy 
that "In the classfile, the type annotations are copied to the class 
declaration and to its instantiation (new expression)."

In June 2018, I do not mind whether @TA appears as CLASS_EXTENDS only, 
or as CLASS_EXTENDS + NEW. If you and Werner have agreed on 
CLASS_EXTENDS only, and if your fix (which is mostly deletion) makes the 
recording of both @TA and @TB more reliable, then I defer to your decision.

Alex


More information about the compiler-dev mailing list