Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 309414

Summary: Inconsistent Compile Result Between APT and JDK
Product: [Eclipse Project] JDT Reporter: Emac Shen <bishen>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: eclipse
Version: 3.5.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
a test java project none

Description Emac Shen CLA 2010-04-15 23:29:58 EDT
Build Identifier: M20090917-0800

Given the annotation usage below (see attached project), the class is compiled well in eclipse but not in command line via javac command.

public class MyClass {

	public static void main(String[] args) {
		MyClass c = new MyClass();
		c.doNothing();
	}

	@MyAnnotation(transformer = { ClassA.class, ClassB.class, })
	public void doNothing() {
		System.out.println("Do nothing");
	}
	
}

I assume eclipse APT plugin is doing some optimization in this case which leads to inconsistent results and it definitely will confuse user and break certain cases.

Reproducible: Always

Steps to Reproduce:
1.import the attached project
2.invoke "Project-Clean"
3.see it compiles well in eclipse.
4.open command line and navigate to the project folder
5.compile the classes using "javac"
6.see the compile fails.
Comment 1 Emac Shen CLA 2010-04-15 23:32:17 EDT
Created attachment 165041 [details]
a test java project
Comment 2 Emac Shen CLA 2010-04-15 23:40:50 EDT
Forgot to point out that the issue appears if and only if there's an extra comma in the annotaion reference:

 @MyAnnotation(transformer = { ClassA.class, ClassB.class, })

If I remove the comma, it works fine.
Comment 3 Walter Harley CLA 2010-04-16 00:12:26 EDT
This is a longstanding javac bug.  Eclipse is correct.  The Java Language Spec (section 9.7) clearly states that the trailing comma is permitted in a list of annotations.

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