Bug: JMH APT processor claims all annotations
aleksey.shipilev at gmail.com
Mon Sep 5 09:19:02 UTC 2016
Later this week, if everything is in order.
On 09/05/2016 12:13 PM, Dimitar Dimitrov wrote:
> Thank you! Any idea when to expect a release?
> On Mon, Sep 5, 2016, 16:37 Aleksey Shipilev <aleksey.shipilev at gmail.com
> <mailto:aleksey.shipilev at gmail.com>> wrote:
> 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.
> > 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
> > 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