JDK-8057919 Class.getSimpleName() should work for non-JLS compliant class names

John Rose john.r.rose at oracle.com
Tue Jun 16 05:08:39 UTC 2015


On Jun 14, 2015, at 7:25 PM, David Holmes <david.holmes at oracle.com> wrote:
> 
> 
> Which reflection method are you referring to? Class.isAnonymousClass is defined in terms of getSimpleName():
> 
> public boolean isAnonymousClass() {
>    return "".equals(getSimpleName());
> }

That might be an issue here.  Just as (String)null and (String)"" are distinct values in Java, in the class file a CP ref of zero differs from a CP ref to a CONSTANT_Utf8 of the empty string "".  But the method Class.isAnonymousClass does not make a distinction between those two cases, which might sometimes lead to confusion.  I would view this as a bug in Class.isAnonymousClass.

— John


More information about the core-libs-dev mailing list