Possible Annotation Processor JavaC Bug

Mark Derricutt mark at talios.com
Fri Jun 8 18:45:27 PDT 2012


The problem we were trying to diagnose was mostly to do with a recent 
change in the Apache Maven build tool, as part of the new 
maven-compiler-plugin/plexus-javac-compiler releases, the same instance 
of the javac compiler is reused across modules in a multi-module build.

This both lowers memory and increases the speed of a multi-module 
compile project.

Yesterday we introduced an annotation processor into one of those 
modules, and found that even tho the jar containing the module wasn't 
in the classpath of subsequent modules, the annotation processor was 
still running as part of its build.

- top level project
  - module a
    > adds jar_with_processor
    > processor runs
 - module b
   > processor also runs

No changes were made to the javac command line to specify or limit 
which processors should be run, which causes javac to auto-discover 
annotation processors based on their META-INF contents.

Looking thru the javac sources, it looked like this discovery process 
is handled at construction time ( I can't recall off hand if this was 
actually in the constructor, or just 'around' the construction ). We 
did spot a  context object which is reused over subsequent compilation 
calls so I'm wondering if the processors to run are somehow tracked in 
here, and not being reset/cleared with subsequent compilation jobs with 
different classpaths.

The maven-compiler-plugin also added options to fallback to always 
creating a new instance of Javac [1], but I've not yet had a chance to 
test that and see if that resolves the problem.

My guess is this is more a maven-plugin bug with its attempts at 
reusing javac.

Good to know the code in JavaCompiler is as intended, the 
multi-assignment just jumped out at me as not looking overly kosher so 
thought I'd query it :)



On Sat Jun  9 03:41:03 2012, Jonathan Gibbons wrote:
> Mark,
> What is your underlying "strange problem with annotation processors"?
> The code in JavaCompiler is as intended, and is not itself a javac bug.
> -- Jon

More information about the compiler-dev mailing list