Bug 206590 - AJC is too restrictive on generics
Summary: AJC is too restrictive on generics
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.5.3   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 1.6.0 M1   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-10-17 05:34 EDT by Joachim Rousseau CLA
Modified: 2008-01-22 12:26 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joachim Rousseau CLA 2007-10-17 05:34:02 EDT
The following code compile OK with 
 - Eclipse 3.2.2 build M20070212-1330, 
 - Sun javac 1.5.0_05-b05
 - Sun javac 1.6.0-b105
But do not compile with AJC 1.5.3

/** 
 * {@inheritDoc}
 */
@Override
public void setAsText(String text) throws IllegalArgumentException {
    value = Enum.valueOf(value.getClass(), text);
}
Actual behaviour:
Error from AJC compiler : 
"Bound mismatch: The generic method valueOf(Class<T>, String) of type Enum<E> is not applicable for the arguments (Class<capture-of ? extends Enum<E>>, String). The inferred type capture-of ? extends Enum<E> is not a valid substitute for the bounded parameter <T extends Enum<T>>"

Expected behaviour : 
Compilation OK with 1 warning, like with Sun & Eclipse compilers.

Workaround:
/** 
 * {@inheritDoc}
 */
@Override
public void setAsText(String text) throws IllegalArgumentException {
    Class enumClass = value.getClass();
    value = Enum.valueOf(enumClass, text);
}
Comment 1 Joachim Rousseau CLA 2007-10-17 05:35:55 EDT
Note : the code I posted is excerpt from an EnumPropertyEditor to bind a String to an enum value (part of a Web framework).
Comment 2 Andrew Clement CLA 2007-10-17 05:42:17 EDT
As you have proved, by checking that it works fine in Eclipse 3.2.2, this is a bug because AspectJ1.5.3 is based on the Eclipse 3.1 compiler.  The compiler upgrade will occur in the AspectJ1.6 release.
Comment 3 Andrew Clement CLA 2008-01-22 12:26:07 EST
If there was a test program here, I'd test it - but I guess I'll just have to assume it is fixed.  AJDT 1.5.2 and AspectJ1.6.0m1 are now available, based on the  Eclipse 3.3 compiler.