JMH does not correctly handle Enum params that override toString()
Anuraag Agrawal
anuraaga at gmail.com
Sun Dec 24 15:48:43 UTC 2017
Hi all,
Currently, JMH uses Enum.toString() to convert enum params to string for
specification from the @Param annotation or the command line. This string,
is then passed into Enum.valueOf when running the benchmark.
However, Java explicitly allows enums to override toString() to something
that doesn't match the descriptor name
https://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html#toString()
Instead, name() should be used when round-tripping through valueOf is
required
https://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html#name()
This affects the reflection and ASM generators. Annotation processor is
unaffected since it directly reads the declaration token.
The patch is simple and I've attached it, but could not find any tests that
round-trip reflection/ASM benchmarks from compile -> run (the issue only
affects running a benchmark, the compile succeeds). if this patch makes
sense, any advice on writing a regression test would be appreciated.
Thanks,
- Anuraag
More information about the jmh-dev
mailing list