Scala/Kotlin users: beware of mistreated annotation targets

Aleksey Shipilev aleksey.shipilev at oracle.com
Thu May 8 15:30:00 UTC 2014


Hi there,

If you are using JMH to benchmark Scala and Kotlin, then you should look
carefully where you put the JMH annotations. Scala/Kotlin compilers are
not treating @Target-s well, and therefore you can place JMH annotations
in the places unknown to annotation handlers, and so they go unprocessed
and unreported as errors.

E.g. you are able to compile and run:

 class B {
    @State(Scope.Benchmark)
    val r = _;
 }

...which is obviously nonsensical. We check lots of semantic things
about annotations, but we also leverage the @Target checks guaranteed by
annotations themselves. I'm not sure this is fixable in easy and
complete manner in JMH code, and further it is really a language
compiler bug :)

Vote up the relevant issues if you want this fixed:
  https://issues.scala-lang.org/browse/SI-4242
  http://youtrack.jetbrains.com/issue/KT-1153

Thanks,
-Aleksey.

P.S. Groovy seem not affected, nice interop!




More information about the jmh-dev mailing list