JDK-7174857 : AnnotationProcessor fails to run if unresolved static imports are present
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2012-06-06
  • Updated: 2012-09-06
  • Resolved: 2012-06-07
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b20)
Java HotSpot(TM) Server VM (build 23.0-b21, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux tiwe 3.2.0-24-generic-pae #39-Ubuntu SMP Mon May 21 18:54:21 UTC 2012 i686 i686 i386 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
The problem occurs when trying to run a AnnotationProcessor against source code which has an unresolved static import.

The AnnotationProcessor is not run and the subsequent compilation fails often as well, since the generated sources are not available

The problem doesn't seem to occur for static wildcard imports

REGRESSION.  Last worked in version 6u31

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
- Create an annotation processor that creates a class with static members

- Define a static import of static member that will be created via the annotation processor

e.g.
  import static com.example.project.domain.QEmployee.employee;

- Run the annotation processor (javac with APT processing only)

- Compile


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Annotation processor is called, generated sources will be available
ACTUAL -
Annotation processor is not called, generated sources won't be available

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Example errors from javac call

/home/tiwe/work/workspace/test/src/main/java/com/example/project/service/EmployeeService.java:3: error: cannot find symbol
import static com.example.project.domain.QEmployee.employee;
                                        ^
  symbol:   class QEmployee
  location: package com.example.project.domain
/home/tiwe/work/workspace/test/src/main/java/com/example/project/service/EmployeeService.java:3: error: static import only from classes and interfaces
import static com.example.project.domain.QEmployee.employee;
^
/home/tiwe/work/workspace/test/src/main/java/com/example/project/service/EmployeeService.java:12: error: cannot find symbol
        return from(employee).list(employee);
                                   ^
  symbol:   variable employee
  location: class EmployeeService
/home/tiwe/work/workspace/test/src/main/java/com/example/project/service/EmployeeService.java:12: error: cannot find symbol
        return from(employee).list(employee);
                    ^
  symbol:   variable employee
  location: class EmployeeService
4 errors


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
  EmployeeService.java:

package com.example.project.service;

// QEmployee is a Querydsl generated mirror class
import static com.example.project.domain.QEmployee.employee;
import java.util.List;
// JPA entity classes
import com.example.project.domain.Employee;

public class EmployeeService extends AbstractService{
    
    public List<Employee> getEmployees() {
        return from(employee).list(employee);
    }

}

The static import is relevant, the rest not really

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Using static wildcard imports instead

Comments
PUBLIC COMMENTS This issue is currently being fixed and will be available soon. In the meantime, please use the workaround.
07-06-2012