JMH error Annotation generator had thrown the exception. java.lang.ClassCastException

Aleksey Shipilev shade at redhat.com
Mon Mar 2 17:45:32 UTC 2020


On 3/2/20 6:28 PM, Vipin Sharma wrote:
> package org.sample;import org.openjdk.jmh.annotations.Benchmark;import
> java.util.EnumSet;public class MyBenchmark {
>     @Benchmark
>     public static <E extends Enum<E>> EnumSet<E> test(E param) {
>         return null;
>     }}

> COMPILATION ERROR : [INFO]
> -------------------------------------------------------------[ERROR]
> Annotation generator had thrown the exception.
> java.lang.ClassCastException: class
> com.sun.tools.javac.code.Symbol$TypeVariableSymbol cannot be cast to
> class javax.lang.model.element.TypeElement
> 
> Is there anything wrong with the benchmark code?

Plenty. Think about it for a minute: JMH would need to call @Benchmark method. What it should call
that method *with*? JMH would normally complain "param" is something weird, but it crashed before
that happened. Even after JMH would fix that part, the benchmark would still be incorrect.

-- 
Thanks,
-Aleksey



More information about the jmh-dev mailing list