RFR: 8342206: Convenience method to check if a constant pool entry matches nominal descriptors

Adam Sotona asotona at openjdk.org
Tue Feb 11 08:06:10 UTC 2025


On Tue, 11 Feb 2025 02:26:57 GMT, Chen Liang <liach at openjdk.org> wrote:

> The ClassFile API promotes usage of constant nominal descriptors over literal strings. However, for `class` file parsing, currently the efficient way to check if a constant pool entry matches a desired descriptor is via unrolling them back to strings. However, string unrolling is ugly, and often times confusing, such as internal names versus field descriptors.
> 
> As a result, I propose to provide new methods that compare constant pool entries with the potential symbolic descriptors they represent. This is no less efficient as checking raw string equality, avoids exceptional failure behaviors of conversion to symbolic descriptors, and avoids potential programmer errors stemming from raw string handling. See the CSR for a full story.

src/java.base/share/classes/java/lang/classfile/constantpool/Utf8Entry.java line 95:

> 93:      * @since 25
> 94:      */
> 95:     boolean equalsSymbol(ClassDesc desc);

Ambiguity of class internal name vs. descriptor serialization might be confusing:

classEntry.equalsSymbol(classDesc) != classEntry.name().equalsSymbol(classDesc)

I think it should be more highlighted to avoid mistakes.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/23548#discussion_r1950390119


More information about the core-libs-dev mailing list