On 9/10/2015 4:23 PM, Jonathan Gibbons wrote:
On 09/08/2015 06:12 PM, Alex Buckley wrote:
I confirm (JDK 8u40) that in an instance/static initializer, where a
local variable declaration includes an annotated type, there is no
RuntimeVisibleTypeAnnotations attribute emitted for the type
annotation! This is so even when the correct meta-annotations appear
on the declaration of the annotation type:

  @Target(ElementType.TYPE_USE)
  @Retention(RetentionPolicy.RUNTIME)

In a ctor, the same local variable declaration does cause a
RuntimeVisibleTypeAnnotations attribute to be emitted for the type
annotation.

I assume the difference stems from the fact that an annotation on a
local variable declaration (the declaration, not its type) was
traditionally never emitted into the class file, regardless of
@Target. In SE 8, an annotation on the type of a local variable
declaration can be emitted into the class file, but presumably some
old code in javac is special-casing initializers and wasn't updated to
understand type annotations therein.

Jon,

Can you confirm my presumption?

I could believe there is a bug in this area, if that is what you are
asking.

javac bug filed as JDK-8136419.

Alex

Reply via email to