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

Liam Miller-Cushon cushon at google.com
Thu Jul 26 16:04:47 UTC 2018


On Wed, Jul 11, 2018 at 7:28 PM Werner Dietl <wdietl at gmail.com> wrote:

> Maybe `copyNewClassAnnotationsToOwner` should now be renamed to
> `propagateNewClassAnnotationsToOwner`
>

Thanks, done.

JDK-8207018 seems very related to the current issue, so it would seem
> worth-while to fix it at the same time. I added a comment there.
>

I investigated JDK-8207018.

The parser currently attaches annotations on anonymous class declarations
to the modifiers tree of the JCNewClass, and relies on the type annotation
handling to disambiguate declaration and type annotations and move the type
annotations to the super-type:
http://hg.openjdk.java.net/jdk/jdk/file/220c9188db4f/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java#l2165
. The disambiguation is incorrectly moving the annotations to the
inner-most type of the super-type, instead of the 'left-most' type that
appeared in source.

I think this logic may have been left over from an earlier iteration of
type annotation implementation, since declaration annotations on anonymous
class declarations are illegal, so it's safe to remove that parser logic
and attach any annotations to the super-type. With that simplification the
compiler still (correctly) rejects any declaration annotations that appear
on anonymous class declarations. The disambiguation currently performed in
TypeAnnotations becomes unnecessary, and JDK-8207018 is fixed.

Here's the updated webrev:
http://cr.openjdk.java.net/~cushon/8198945/webrev.04/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20180726/edf7aea7/attachment.html>


More information about the compiler-dev mailing list