Class.getSimpleName not suitable for non-Java classes

Aleksey Shipilev shade at
Fri Mar 17 13:18:30 UTC 2017

On 03/16/2017 02:16 PM, Daniel Armak wrote:
> Thanks! This resolves the issue of confusing a class named "int" with the
> primitive type.
> Unfortunately, it doesn't resolve the issue of getSimpleName throwing due to
> JDK-8057919, because getCanonicalName calls getSimpleName. 
> Actually, I think getCanonicalName isn't a good idea regardless, because it
> returns null for anonymous classes, and I think you should use getName instead
> in those cases. So you might as well use getName also if getCanonicalName
> throws, or just always use it.

The trouble with using getName() is that it replies the JVM signature like C],
which is not very human-readable.

These two fixes should solve the issue from JDK-8057919 and handle anonymous
classes well:

Check now, please?


More information about the jol-dev mailing list