JDK-7129225 : javac fails to run annotation processors when star import of package of gensrc
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7u2
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2012-01-11
  • Updated: 2012-02-24
  • Resolved: 2012-02-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u4Fixed 8 b25Fixed
Related Reports
Relates :  
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
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.
25-01-2012

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.
25-01-2012

WORK AROUND Use explicit, not wildcard, imports.
11-01-2012

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