On Fri, 13 Mar 2026 15:04:11 GMT, Marcono1234 <[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 278:
>
>> 276: * <p>
>> 277: * To print an access flags value for debug output, consider using
>> the
>> 278: * format {@code %04x} instead of this method; this method omits
>> all class
>
> Maybe this should say "hex format" or similar to make it immediately obvious
> what this pattern does?
>
> Suggestion:
>
> * hex format {@code %04x} instead of this method; this method omits all
> class
I used 'format' because you can use this out of the box in String.format,
printf, and String.formatted. 'hex format' I'm afraid would make users think
they need to use java.util.HexFormat, I haven't tried using that to print yet.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/30093#discussion_r2932029674