Problem with type annotations on a type parameter
Werner Dietl
wdietl at gmail.com
Thu Apr 25 20:58:38 PDT 2013
Jon, Steve,
thanks for raising this issue:
On Thu, Apr 25, 2013 at 2:10 PM, Jonathan Gibbons
<jonathan.gibbons at oracle.com> wrote:
> So, the bad news .. or at least, a complication for you, if you haven't
> already considered this ...
>
> I know that some of the type anno positions involve byte code offsets --
> i.e. for type annos within a method body. But byte-code offsets are not
> computed until Gen, which occurs after erasure (TransTypes). So what about
> annotations on type parameters within a method body -- do you handle them?
> e.g.
>
> Object m() {
> List<@NonNull String> list = new ArrayList<@NonNull String>();
> return list;
>
> }
It looks to me that the code does what it's supposed to do, by
manually using javap on such an example.
The reason is that setting the bytecode offset works on the symbols,
which already contain all type annotations - even after erasure.
However, looking at unit tests like
langtools/test/tools/javac/annotations/typeAnnotations/referenceinfos/NewObjects.java
the bytecode offset is always ignored:
offset = ReferenceInfoUtil.IGNORE_VALUE
Also, in "referenceinfos" there is no equivalent to
newlocations/LocalVariables.java
Steve, can you think of a way to best test for correct offsets? We
should ensure that IGNORE_VALUE is not used too much.
Thanks,
cu, WMD.
> 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