RFR: 8278863: Add method ClassDesc::ofInternalName

Jorn Vernee jvernee at openjdk.org
Fri Jun 17 15:10:52 UTC 2022


On Fri, 17 Jun 2022 14:19:11 GMT, Adam Sotona <asotona at openjdk.org> wrote:

> The symbolic constants API (`java.lang.constant`) was designed, in part, to provide bytecode parsing and generation APIs with a validated, common, symbolic form for constants in Java class files. 
> 
> There is an easy way to create a `ClassDesc` from a binary name (`ClassDesc::of`) or a field descriptor (`ClassDesc::ofDescriptor`) but not from an internal name. But, the internal name is common in low-level bytecode-manipulation code. 
> 
> This patch adds `ClassDesc::ofInternalName` static factory method that creates a `ClassDesc` from class internal name.
> Class internal name validation and extended ClassDescTest are also parts of this patch.
> 
> CSR is linked with the issue.
> 
> Please review.
> 
> Thank you,
> Adam

I've worked with ClassDesc quite a bit as well, and often found myself wanting to do the opposite. i.e. if I have a `ClassDesc`, convert it to an internal name string (to give to ASM).

There are also methods to get the descriptor, as well as display name & package name from a `ClassDesc`. So, I'd like to suggest adding a method to get the internal name from a `ClassDesc` as well.

test/jdk/java/lang/constant/ClassDescTest.java line 136:

> 134: 
> 135:         List<ClassDesc> stringClassDescs = Arrays.asList(ClassDesc.ofDescriptor("Ljava/lang/String;"),
> 136:                                                         ClassDesc.ofInternalName("java/lang/String"),                                                        ClassDesc.of("java.lang", "String"),

Looks like an accidental duplicate of `ClassDesc.of("java.lang", "String")`?
Suggestion:

                                                        ClassDesc.ofInternalName("java/lang/String"),

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

PR: https://git.openjdk.org/jdk/pull/9201


More information about the core-libs-dev mailing list