Problem with type annotations on a type parameter

Werner Dietl wdietl at gmail.com
Thu Apr 25 21:09:09 PDT 2013


Jon, Steve,

On Thu, Apr 25, 2013 at 2:27 PM, Jonathan Gibbons
<jonathan.gibbons at oracle.com> wrote:
> Werner,
>
> Is this is a simple answer to the problem?
>
> I'm looking at TypeAnnotations.TypeAnnotationPositions.visitNewClass, round
> about 1155.
>
>
>         @Override
>         public void visitNewClass(JCNewClass tree) {
>             if (tree.def != null &&
>                     !tree.def.mods.annotations.isEmpty()) {
>                 JCClassDecl classdecl = tree.def;
>                 TypeAnnotationPosition pos = new TypeAnnotationPosit
>
> You are checking tree.def.mods.annotations but what about annos embedded
> within tree.def?

Note that the only thing that happens in that then-block is setting
the TA-position for the top-level annotations on the "new".
The call to separateAnnotationsKinds does not recurse into the tree.def.

It might rather be the comment at the end of this file:

            // The class body will already be scanned.
            // scan(tree.def);

However, if I add that scan, the behavior is inverted: if I don't
instantiate the inner class, I get only a type annotation; if I
instantiate the inner class I get only a declaration annotation.

cu, WMD.


> -- Jon
>
> On 04/04/2013 06:02 PM, Werner Dietl wrote:
>>
>> Jon, Steve, all,
>>
>> I'm debugging some strange behavior and I would appreciate a quick look by
>> somebody else. I'm probably missing something very obvious.
>>
>> Take the attached class that contains a class nested within an anonymous
>> class.
>> Compile with the type-annotations javac and you'll get this output:
>>
>> ClassWriter: Position UNKNOWN in type annotation: @TA
>> ClassWriter: Position UNKNOWN in type annotation: @TA
>>
>> That's bad, as it means that the type annotation is not written. We
>> confirm this by running javap:
>>
>> javap -v NestedTest\$1\$Inner.class
>>
>> Nothing on the type parameter.
>>
>> The strange thing is that this works if we remove the declaration of field
>> i1.
>> It also works if instead of a method type parameter we declare a method
>> parameter, or a class type parameter, or if the class is outside of the
>> anonymous class.
>>
>> Does anybody understand the dependency between field i1 and the type
>> parameter X?
>>
>> Steve: could you expand the tests in
>> tools/javac/annotations/typeAnnotations/referenceinfos/ to ensure that
>> annotations in anonymous classes and lambdas work as expected?
>> Please also add a failing test for this.
>>
>> Thanks,
>> cu, WMD.
>>
>> --
>> http://www.google.com/profiles/wdietl
>
>



--
http://www.google.com/profiles/wdietl


More information about the type-annotations-dev mailing list