Bug: JMH APT processor claims all annotations

Aleksey Shipilev aleksey.shipilev at gmail.com
Mon Sep 5 07:37:49 UTC 2016

Yes, sorry about that, should be fixed with:


On 08/11/2016 07:10 AM, Dimitar Dimitrov wrote:
> Problem:
> ------------
> When a codebase using JMH also uses other annotation processors (i.e.
> Lombok, Dagger 2, etc) The other processors will not get a chance to run if
> they are ordered after JMH.
> Root cause:
> ----------------
> The JMH BenchmarkProcessor#process() method returns unconditionally true
> regardless of whether it processed an annotation or not.
> http://hg.openjdk.java.net/code-tools/jmh/file/397891feda1b/jmh-generator-annprocess/src/main/java/org/openjdk/jmh/generators/BenchmarkProcessor.java
> According to the Javadoc, if a processor returns true, it will "claim" the
> annotation for itself and no other processors will be given a chance to
> process it.
> Proposed fix:
> ------------------
> I am not deeply familiar with JMH, but for what I know, it has a closed set
> of annotations, so line 41 in on BenchmarkProcessor.java to:
>      SupportedAnnotationTypes("org.openjdk.jmh.annotations.*")
> If JMH allows user-defined annotations things get a bit more complicated.
> If the user-defined annotations are known in advance, one can override
> Processor#getSupportedAnnotationTypes()
> if there is a need to dynamically support user defined annotations, one
> needs to inspect the first arg of the process() method and sure that it
> returns true only in cases where all annotations are for JMH.
> AFinally, a simpler option is for the main processor to always return false
> and add a separate processor that doesn't do anything else but claim the
> known JMH annotations. That covers most cases, though that may result in
> javac warning (-Xlint:processing) with user-defined annotations.
> Best regards,
> Dimitar

More information about the jmh-dev mailing list