Change of the toString implementation for annotations

Rafael Winterhalter rafael.wth at gmail.com
Thu Jul 28 13:38:09 UTC 2016


Hi Joe,
thank you for your answer. Can I ask for the rationale of using {} instead
of [] only for classes? If the goal was to come closer to the source code
representation, would this not imply to use curly braces for all array of
an annotation?
Thank you for your time! Best regards, Rafael

2016-07-19 4:13 GMT+02:00 joe darcy <joe.darcy at oracle.com>:

> Hello Rafael,
>
> On 7/18/2016 5:43 PM, Rafael Winterhalter wrote:
>
>> Hello,
>> I recognized a failing test on Java 9 caused by a changed return value
>> returned by toString on an annotation with a class-property.
>>
>> When calling toString on an annotation: @interface Foo { Class<?> value();
>> } instantiated as @Foo(Bar.class) with Java 8 it would be printed as:
>>
>> @Foo(class Bar)
>>
>> while in Java 9 it is printed as:
>>
>> @Foo(Bar.class)
>>
>> Is this change intended? I do not see a big benefit of this implementation
>> change and it could break code. In my case, the problem is not that big,
>> it
>> is an easy fix but still, I found it a bit surprising.
>>
>>
> I pushed the change your test noticed; it was done as part of
>
>     JDK-5040830: (ann) please improve toString() for annotations
> containing exception proxies
>     https://bugs.openjdk.java.net/browse/JDK-5040830
>
> The basic rationale for the change is that "Foo.class" is the syntax that
> appears when annotations are in source code so the toString() form should
> generally reflect that.
>
> Thanks for running your project against JDK 9 builds; HTH,
>
> -Joe
>


More information about the core-libs-dev mailing list