On Thu, 5 Mar 2026 17:54:14 GMT, Chen Liang <[email protected]> wrote:
> In project valhalla development, we discovered that `Modifier.toString`
> becomes more problematic than helpful: there's now a mix-and-match of
> modifiers from access flags and other class file sources, for example,
> classes now can have ACC_IDENTITY, which clashes with ACC_SYNCHRONIZED, and
> the correct modifier to reflect, "value", must be deduced by the users
> manually.
>
> With fewer bits available for the access flags, it becomes more apparent that
> future source modifiers will no longer be reflected by `Modifier.toString`,
> and future access flags are more likely to be reflected incorrectly. Thus, we
> should dissuade users from this API in the long run.
>
>> This method tries to describe the source modifiers from an access flags
>> value. Since the introduction of this API, new source modifiers are
>> often represented by `class` file constructs other than access
>> flags, and access flags values in different `class` file
>> structures have different interpretations. As a result, the source
>> modifiers reported by this API may be incomplete or incorrect.
>>
>> The source modifiers of a declaration should be reconstructed manually,
>> by examining its reflective object. In addition, the reflective object
>> methods that provide user-friendly text representations, such as
>> `Class#toGenericString()`, render the source modifiers.
>>
>> The access flags of a declaration, with the correct interpretation, can
>> be obtained from the `accessFlags()` methods on the reflective
>> objects, such as `Class#accessFlags()`.
>>
>> To print an access flags value for debug output, consider using the
>> format ``%04x` instead of this method; this method omits all class
>> file access flags without a corresponding source modifier.
src/java.base/share/classes/java/lang/reflect/Modifier.java line 51:
> 49: * <li>The same bit may represent different flags in different
> structures, like
> 50: * {@code 0x0040} represents {@link #VOLATILE ACC_VOLATILE} in fields
> and
> 51: * {@code ACC_BRIDGE} in interfaces</li>
`ACC_BRIDGE` applies to all bridge methods, not only those on interfaces.
Suggestion:
* {@code ACC_BRIDGE} in methods</li>
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/30093#discussion_r2906623372