Summary: | Compilation error on generic capture/type inference with AJC 1.8.0 | ||||||
---|---|---|---|---|---|---|---|
Product: | [Tools] AspectJ | Reporter: | Frank Pavageau <frank.pavageau> | ||||
Component: | Compiler | Assignee: | aspectj inbox <aspectj-inbox> | ||||
Status: | NEW --- | QA Contact: | |||||
Severity: | major | ||||||
Priority: | P3 | CC: | aclement | ||||
Version: | 1.8.0 | ||||||
Target Milestone: | --- | ||||||
Hardware: | PC | ||||||
OS: | Linux | ||||||
Whiteboard: | |||||||
Bug Depends on: | 434118 | ||||||
Bug Blocks: | |||||||
Attachments: |
|
Hey. Thanks for the report - are you also going to raise a JDT bug? Yes, I raised a JDT bug and set it as a dependency of this one. |
Created attachment 242705 [details] Test case The attached example fails to compile with AJC 1.8.0 (or a snapshot of 1.8.1) but compiles perfectly with 1.6 or 1.7. It also compiles with javac from JDK 6, 7 or 8. [ERROR] /home/pavageau/devs/aspectj/wildcard-capture/src/main/java/WildcardCapture.java:3:0::0 The method valueOf(Class<T>, String) in the type Enum is not applicable for the arguments (Class<capture#2-of ? extends Enum>, String) The example class has 3 methods with minute variations, only the first one fails to compile. If I specify the generic parameter on the method call, or extract the result as a variable, it works. To be honest, it seems to be a problem with ECJ, as I get the same error when using the most recent snapshot of ECJ deployed to Maven Central: ~/devs/aspectj/wildcard-capture/src/main/java$ java -jar ~/.m2/repository/org/eclipse/jdt/core/compiler/ecj/P20140317-1600/ecj-P20140317-1600.jar -1.8 -deprecation WildcardCapture.java ---------- 1. ERROR in /home/pavageau/devs/aspectj/wildcard-capture/src/main/java/WildcardCapture.java (at line 3) return Enum.valueOf(clazz.asSubclass(Enum.class), value); ^^^^^^^ The method valueOf(Class<T>, String) in the type Enum is not applicable for the arguments (Class<capture#2-of ? extends Enum>, String) ---------- 2. WARNING in /home/pavageau/devs/aspectj/wildcard-capture/src/main/java/WildcardCapture.java (at line 7) return Enum.valueOf(clazz.<Enum>asSubclass(Enum.class), value); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Type safety: Unchecked invocation valueOf(Class<capture#4-of ? extends Enum>, String) of the generic method valueOf(Class<T>, String) of type Enum ---------- 3. WARNING in /home/pavageau/devs/aspectj/wildcard-capture/src/main/java/WildcardCapture.java (at line 7) return Enum.valueOf(clazz.<Enum>asSubclass(Enum.class), value); ^^^^ Enum is a raw type. References to generic type Enum<E> should be parameterized ---------- 4. WARNING in /home/pavageau/devs/aspectj/wildcard-capture/src/main/java/WildcardCapture.java (at line 11) Class<? extends Enum> enumType = clazz.asSubclass(Enum.class); ^^^^ Enum is a raw type. References to generic type Enum<E> should be parameterized ---------- 5. WARNING in /home/pavageau/devs/aspectj/wildcard-capture/src/main/java/WildcardCapture.java (at line 12) return Enum.valueOf(enumType, value); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Type safety: Unchecked invocation valueOf(Class<capture#7-of ? extends Enum>, String) of the generic method valueOf(Class<T>, String) of type Enum ---------- 5 problems (1 error, 4 warnings) ECJ also sees warnings when javac doesn't, by the way. So I should probably report the problem to ECJ (in JDT/Core, I guess), but this bug is still needed so you know you'll have to upgrade if/when it's fixed.