-
CSR
-
Resolution: Unresolved
-
P4
-
None
-
source
-
minimal
-
Addition of a new method in a sealed hierarchy has minimal compatibility risk.
-
Java API
-
SE
Summary
Add a new utility method, ClassEntry::equalsSymbol(ClassDesc)
, to facilitate easy comparison of ClassEntry
with ClassDesc
constants.
Problem
ClassEntry
is often compared against desired classes during bytecode transformation, such as ce.name().equalsString("java/lang/System")
if we want to detect if a call is to System::exit
.
However, we intend to reduce the use of "internal names" which is a legacy baggage. Such internal names are not available as constants, so writing them manually is error-prone.
We have constants for ClassDesc
, but the current way to compare ClassEntry
to ClassDesc
is ce.asSymbol().equals(cd)
. This approach has a few problems:
- The conversion of
ClassEntry
toClassDesc
viaasSymbol
involves unnecessary transformations and is performance-wise undesirable. - If the
ClassEntry
points to aUtf8Entry
with invalid content,asSymbol
will unexpectedly fail.
Solution
To facilitate good programming habits with the ClassFile API, we need a new ClassEntry::equalsSymbol(ClassDesc)
, which:
- Allows usage of known constants, such as
equalsSymbol(CD_System)
; - Is as efficient as
name().equalsString("java/lang/System")
; - Does not fail if the
ClassEntry
itself is invalid.
Specification
/**
* {@return whether this class entry describes the same class as the provided symbol}
*
* @param symbol the symbol to compare to
*/
boolean equalsSymbol(ClassDesc symbol);
- csr of
-
JDK-8342206 Convenience method to check if a constant pool entry matches nominal descriptors
- Open