United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7129225 javac fails to run annotation processors when star import of package of gensrc
JDK-7129225 : javac fails to run annotation processors when star import of package of gensrc

Details
Type:
Bug
Submit Date:
2012-01-11
Status:
Closed
Updated Date:
2012-02-24
Project Name:
JDK
Resolved Date:
2012-02-24
Component:
tools
OS:
linux
Sub-Component:
javac
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
7u2
Fixed Versions:

Related Reports
Backport:
Relates:

Sub Tasks

Description
After unpacking http://netbeans.org/bugzilla/attachment.cgi?id=114753 and running 'mvn -f netbeans-generation-issue/sampleprocessor/pom.xml install', if (with JAVA_HOME set to JDK 7u1 or u2) you run 'mvn -f netbeans-generation-issue/generatingissue/pom.xml clean compile' you will get an error:

[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ generatingissue ---
[INFO] Compiling 2 source files to /tmp/netbeans-generation-issue/generatingissue/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /tmp/netbeans-generation-issue/generatingissue/src/main/java/jp/javelindev/netbeans/generatingissue/ClassWithIssue.java:[4,0] error: package jp.javelindev.netbeans.generatingissue.impl does not exist
[ERROR] /tmp/netbeans-generation-issue/generatingissue/src/main/java/jp/javelindev/netbeans/generatingissue/ClassWithIssue.java:[14,32] error: cannot find symbol
[INFO] 2 errors 

Using JDK 6u30 it works:

[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ generatingissue ---
[INFO] Compiling 2 source files to /tmp/netbeans-generation-issue/generatingissue/target/classes
[WARNING] /tmp/netbeans-generation-issue/generatingissue/src/main/java/jp/javelindev/netbeans/generatingissue/ClassWithIssue.java:[4,0] package jp.javelindev.netbeans.generatingissue.impl does not exist
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

Pulling out the actual forked javac command line (obtainable using -X), which includes -verbose, shows that in JDK 7 (or javac built from langtools c747f413d531) no apparent attempt is made to run the annotation processor, though its @SupportedAnnotationTypes matches the annotation in the source file, whereas JDK 6 loads it as expected:

Round 1:
	input files: {jp.javelindev.netbeans.generatingissue.ClassWithIssue, jp.javelindev.netbeans.generatingissue.GenerateOrigin}
	annotations: [jp.javelindev.netbeans.sampleprocessor.SampleAnnotation]
	last round: false
RUNNING...
Processor jp.javelindev.netbeans.sampleprocessor.SampleProcessor matches [jp.javelindev.netbeans.sampleprocessor.SampleAnnotation] and returns true.

The problem seems to go away if you replace the wildcard import with an exact import:

import jp.javelindev.netbeans.generatingissue.impl.GenerateOriginImpl;

Then even JDK 7 javac goes through the required multiple rounds, running the AP.

                                    

Comments
WORK AROUND

Use explicit, not wildcard, imports.
                                     
2012-01-11
PUBLIC COMMENTS

Noticed while evaluating: http://netbeans.org/bugzilla/show_bug.cgi?id=207107
                                     
2012-01-11
EVALUATION

The method MemberEnter.importAll gens an error on
    import xxx.*;

when xxx does not exist.  This error causes the compilation to terminate before annotation processors are run.
                                     
2012-01-25
SUGGESTED FIX

Change MemberEnter.importAll to add the flag
    DiagnosticFlag.RESOLVE_ERROR

to the error it generates.
This causes the compiler to keep going and run the annotation processors.
                                     
2012-01-25



Hardware and Software, Engineered to Work Together