On Mon, 12 Jun 2023 04:52:57 GMT, Chen Liang <li...@openjdk.org> wrote:

>> src/java.base/share/classes/jdk/internal/classfile/impl/Util.java line 103:
>> 
>>> 101:             }
>>> 102:             return descOrInternalName.substring(1, 
>>> descOrInternalName.length() - 1).replace('/', '.');
>>> 103:         } else {
>> 
>> Note that this won’t work right if this method is called with the internal 
>> name of a class whose FQCN starts with `L`, the correct implementation would 
>> be:
>> Suggestion:
>> 
>>         if (descOrInternalName.startsWith("L") && 
>> descOrInternalName.endsWith(";")) {
>>             // descriptors of classes or interfaces
>>             if (descOrInternalName.length() <= 2) {
>>                 throw new IllegalArgumentException(descOrInternalName);
>>             }
>>             return descOrInternalName.substring(1, 
>> descOrInternalName.length() - 1).replace('/', '.');
>>         } else {
>
> Honestly, this API should be changed to take a ClassDesc instead.

In fact, the specification (javadoc) on this method is wrong: it will never 
take an internal name; it only takes descriptors and tries to simulate the 
result of `Class::getName`, since `ClassDesc` lacks such functionality.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/13082#discussion_r1226107958

Reply via email to