Bug 121067 - Array annotation element doesn't return array if curly braces ommited
Summary: Array annotation element doesn't return array if curly braces ommited
Status: RESOLVED DUPLICATE of bug 10
Alias: None
Product: JDT
Classification: Eclipse Project
Component: APT (show other bugs)
Version: 3.1.1   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Theodora Yeung CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-15 10:54 EST by Compl Yue Still CLA
Modified: 2005-12-15 18:28 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Compl Yue Still CLA 2005-12-15 10:54:16 EST
*---
In other words, it is permissible to omit the curly braces when a single-element array is to
be associated with an array-valued annotation type element.
*---
Above is from JLS3.0

But I found if JDT apt env, when an annotation has an array type element, and used with a single-element array but without the optional curly barces, call to get the element value will return a non-array value, and finally caused a runtime ClassCastException.

That's to say, if we have one annotation defined like this:

public @DemoAnno
{
  String[] value();
}

And used it like:

@DemoAnno("whatever")

And we try the following when processing it:

DemoAnno da = Declaration.getAnnotation(DemoAnno.class);
String[] dav = da.value(); // here it returns the String rather than the String array.

And this will finally cause an unchecked ClassCastException.
Comment 1 Theodora Yeung CLA 2005-12-15 18:28:56 EST
This bug has been resolved.

Duplicate of 103241. 
https://bugs.eclipse.org/bugs/show_bug.cgi?id=103241

*** This bug has been marked as a duplicate of 10 ***