RFR (S): Class.getSimpleName() should work for non-JLS compliant class names
vladimir.x.ivanov at oracle.com
Wed Apr 8 15:41:15 UTC 2015
The logic to compute simple name (Class.getSimpleName()) for
inner/nested/local classes is tightly coupled with Java naming scheme
and sometimes fails for classes generated from non-Java code.
Instead of parsing class name and try to extract simple name based on
JLS rules, the fix I propose is to use InnerClasses attribute from the
class file. Simple name is already recorded there.
JVMS-4.7.6: The InnerClasses Attribute
"inner_name_index: If C is anonymous (JLS §15.9.5), the value of the
inner_name_index item must be zero. Otherwise, the value of the
inner_name_index item must be a valid index into the constant_pool
table, and the entry at that index must be a CONSTANT_Utf8_info
structure (§4.4.7) that represents the original simple name of C, as
given in the source code from which this class file was compiled."
Since I consider backporting the fix into 8u60, I'd like to hear
opinions about backward compatibility of such change.
As an alternative solution, I can restore original logic and consult
InnerClasses attribute when class name parsing logic fails.
Testing: regression test, jck-runtime/java_lang, jdk/test/java/lang/
More information about the hotspot-dev