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

Alex Buckley alex.buckley at oracle.com
Tue Jul 3 18:37:11 UTC 2018

On 7/2/2018 7:34 PM, Liam Miller-Cushon wrote:
> On Mon, Jul 2, 2018 at 7:14 PM Werner Dietl <wdietl at gmail.com
> <mailto:wdietl at gmail.com>> wrote:
>     Class Test$1 has no type arguments, so I would find having NEW type
>     annotations on a type argument confusing.
> Ah, right. Thanks for the catch.
>     So I would be for either no NEW type annotations for anonymous class
>     instantiations, or duplicating only the top-level type annotations.
>     For method f() this would generate three type annotations:
>            RuntimeInvisibleTypeAnnotations:
>              0: #22(): NEW, offset=9
>                Test$TA
>              1: #23(): NEW, offset=9, location=[TYPE_ARGUMENT(0)]
>                Test$TB
>              2: #22(): NEW, offset=0
>                Test$TA
>     Duplicating only the top-level type annotations would be my slight
>     preference over no NEW annotations at all.
> I revised the fix to only duplicate top-level annotations:
> http://cr.openjdk.java.net/~cushon/8198945/webrev.02
> <http://cr.openjdk.java.net/~cushon/8198945/webrev.02/>

I am OK with this. To be clear, given this code in a method of class Test:

   new @TA I<@TB Object>() {};
   new @TA J<@TB Object>();

we're going to generate annotations as if the code was:

   new @TA Test$1();
   new @TA J<@TB Object>();

   class Test$1 implements @TA I<@TB Object> {}

(The type_annotation structure for the first @TA has a NEW target_type, 
while the type_annotation structure for the second @TA has a 
CLASS_EXTENDS target_type. Since the structures are not identical, it's 
misleading to say that anything is "duplicated".)


More information about the compiler-dev mailing list