[java.lang.annotation.IncompleteAnnotationException] 9003386: call toString() on String in java.lang.annotation.IncompleteAnnotationException

David Holmes david.holmes at oracle.com
Tue May 28 11:14:50 UTC 2013


<replying on core-libs >

On 28/05/2013 7:27 PM, Alan Bateman wrote:
> On 28/05/2013 10:15, Otávio Gonçalves de Santana wrote:
>> diff --git
>> a/src/share/classes/java/lang/annotation/IncompleteAnnotationException.java
>>
>> b/src/share/classes/java/lang/annotation/IncompleteAnnotationException.java
>>
>> ---
>> a/src/share/classes/java/lang/annotation/IncompleteAnnotationException.java
>>
>> +++
>> b/src/share/classes/java/lang/annotation/IncompleteAnnotationException.java
>>
>> @@ -55,9 +55,9 @@
>>       public IncompleteAnnotationException(
>>               Class<? extends Annotation>  annotationType,
>>               String elementName) {
>> -        super(annotationType.getName().toString() +
>> +        super(annotationType.getName() +
>>                 " missing element " +
>> -              elementName.toString());
>> +              elementName);
>>
>>           this.annotationType = annotationType;
>>           this.elementName = elementName;
>>
> I would suggest bring this clean-up to core-libs-dev. Also the bug for
> this in the bug database is:
>
> 8015470: (ann) IncompleteAnnotationException does not need to call toString

I don't see this as a bug at all - it is an optimization. The explicit 
toString() avoids the String.valueOf call (which will call toString() 
itself) and an additional StringBuffer.append call.

Without the toString you have calls to:

- StringBuilder.append(Object)
- String.valueOf(Object)
- Object.toString()
- StringBuilder.append(String)

with it you have

- Object.toString()
- StringBuilder.append(String)

David

> -Alan



More information about the core-libs-dev mailing list