Skip to content

8379337: Deprecate Modifier.toString#30093

Closed
liach wants to merge 13 commits intoopenjdk:masterfrom
liachmodded:fix/deprecate-modifier-tostring
Closed

8379337: Deprecate Modifier.toString#30093
liach wants to merge 13 commits intoopenjdk:masterfrom
liachmodded:fix/deprecate-modifier-tostring

Conversation

@liach
Copy link
Copy Markdown
Member

@liach liach commented Mar 5, 2026

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.



Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change requires CSR request JDK-8379338 to be approved

Issues

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/30093/head:pull/30093
$ git checkout pull/30093

Update a local copy of the PR:
$ git checkout pull/30093
$ git pull https://git.openjdk.org/jdk.git pull/30093/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 30093

View PR using the GUI difftool:
$ git pr show -t 30093

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/30093.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper Bot commented Mar 5, 2026

👋 Welcome back liach! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Mar 5, 2026

@liach This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8379337: Deprecate Modifier.toString

Reviewed-by: alanb

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 12 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk Bot added hotspot-compiler hotspot-compiler-dev@openjdk.org core-libs core-libs-dev@openjdk.org compiler compiler-dev@openjdk.org labels Mar 5, 2026
@openjdk
Copy link
Copy Markdown

openjdk Bot commented Mar 5, 2026

@liach The following labels will be automatically applied to this pull request:

  • compiler
  • core-libs
  • hotspot-compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk Bot added csr Pull request needs approved CSR before integration rfr Pull request is ready for review labels Mar 5, 2026
@mlbridge
Copy link
Copy Markdown

mlbridge Bot commented Mar 5, 2026

Webrevs

* have a corresponding access flag</li>
* <li>The same bit may represent different flags in different structures, like
* {@code 0x0040} represents {@link #VOLATILE ACC_VOLATILE} in fields and
* {@code ACC_BRIDGE} in interfaces</li>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACC_BRIDGE applies to all bridge methods, not only those on interfaces.

Suggested change
* {@code ACC_BRIDGE} in interfaces</li>
* {@code ACC_BRIDGE} in methods</li>

Copy link
Copy Markdown

@Marcono1234 Marcono1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully these review comments are useful. Feel free to only consider them as suggestions.

* </ol>
* These assumptions are no longer valid:
* <ol>
* <li>Java language modifiers like method modifier {@code default} does not
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe grammar issue: This refers to the plural "modifiers"

Suggested change
* <li>Java language modifiers like method modifier {@code default} does not
* <li>Java language modifiers like method modifier {@code default} do not

* {@code 0x0040} represents {@link #VOLATILE ACC_VOLATILE} in fields and
* {@code ACC_BRIDGE} in interfaces</li>
* </ol>
* To mitigate, {@code Modifier} class only include source modifiers that
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe grammar issue

Suggested change
* To mitigate, {@code Modifier} class only include source modifiers that
* To mitigate, the {@code Modifier} class only includes source modifiers that

* objects, such as {@link Class#accessFlags()}.
* <p>
* To print an access flags value for debug output, consider using the
* format {@code %04x} instead of this method; this method omits all class
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should say "hex format" or similar to make it immediately obvious what this pattern does?

Suggested change
* format {@code %04x} instead of this method; this method omits all class
* hex format {@code %04x} instead of this method; this method omits all class

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

* modifiers that can be applied to a class.
*
* @deprecated
* This method is intended to be used in conjunction with {@link #toString()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link to wrong toString method? toString() is not deprecated only toString(int)?

Suggested change
* This method is intended to be used in conjunction with {@link #toString()
* This method is intended to be used in conjunction with {@link #toString(int)

(same also below for all other occurrences)

* interface (JLS {@jls 9.1.1}).
*
* @deprecated
* This method tries to describe the source modifiers from an access flags
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the methods should be deprecated but I think the @deprecated text will need a few iterations. I think it would be better to start with something like "This method was originally specified to describe the source modifiers ..." rathe rthan "This tries ...".

* {@jls 9.4.3}) and the {@code sealed} and {@code non-sealed} class
* (JLS {@jls 8.1.1.2}) and interface (JLS {@jls 9.1.1.4}) modifiers
* are <em>not</em> represented in this class.
* {@code Modifier} was designed with two assumptions:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the apiNote will need a few iterations on the wording. I don't like it starting with the assumptions and then saying that the assumptions aren't valid. Instead I think it would be better to say that the translation of source modifiers to access flags has evolved since the API was originally introduced. In addition, the bit may represent different flags. The API can still be used for source modifiers that directly map to an access flag. New code is encouraged to use AccessFlags.

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper Bot commented Apr 14, 2026

@liach This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Apr 16, 2026

The total number of required reviews for this PR has been set to 2 based on the presence of this label: hotspot-compiler. This can be overridden with the /reviewers command.

@openjdk openjdk Bot removed the rfr Pull request is ready for review label Apr 16, 2026
@liach
Copy link
Copy Markdown
Member Author

liach commented Apr 16, 2026

/template append
/label remove hotspot-compiler
/reviewers 1 reviewer

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Apr 16, 2026

@liach The pull request template has been appended to the pull request body

@openjdk openjdk Bot removed the hotspot-compiler hotspot-compiler-dev@openjdk.org label Apr 16, 2026
@openjdk
Copy link
Copy Markdown

openjdk Bot commented Apr 16, 2026

@liach
The hotspot-compiler label was successfully removed.

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Apr 16, 2026

@liach
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 1 (with at least 1 Reviewer).

@openjdk openjdk Bot added the rfr Pull request is ready for review label Apr 16, 2026
* <p>
* Java SE 5.0 introduced many new access and property flags, such as {@link
* AccessFlag#SYNTHETIC ACC_SYNTHETIC}. Unlike {@code ACC_SUPER}, these access
* and property flags are reported by the {@code getModifier()} methods.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be getModifiers()?

Suggested change
* and property flags are reported by the {@code getModifier()} methods.
* and property flags are reported by the {@code getModifiers()} methods.

@openjdk openjdk Bot added the hotspot-runtime hotspot-runtime-dev@openjdk.org label Apr 20, 2026
@openjdk
Copy link
Copy Markdown

openjdk Bot commented Apr 20, 2026

@liach hotspot-runtime has been added to this pull request based on files touched in new commit(s).

@liach
Copy link
Copy Markdown
Member Author

liach commented Apr 20, 2026

/label remove hotspot-runtime

@openjdk openjdk Bot removed the hotspot-runtime hotspot-runtime-dev@openjdk.org label Apr 20, 2026
@openjdk
Copy link
Copy Markdown

openjdk Bot commented Apr 20, 2026

@liach
The hotspot-runtime label was successfully removed.

* <p>
* Modifier interpretation is context-sensitive: for example, the bit checked by
* {@link #isSynchronized(int) isSynchronized} only represents the {@code
* synchronized} modifier on methods, so a {@code true} return on a field
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first paragraph uses "flags", the second paragraph switches to "bits", a term that is never used again. The referenced AccessFlags or javax.lang.model.element.Modifier doesn't speak of bits. So I'm wondering if it would be better to say "the modifier checked by ..." rather than "bit checked".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will use "access flags" consistently.

*
* @deprecated
* This method exists solely to support the now-deprecated
* {@link #toString(int) Modifier::toString(int)} method.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would think of changing the first sentence to "This method was originally created to the support ..". The second sentence is good, sends the reader to the new API.

Copy link
Copy Markdown
Contributor

@AlanBateman AlanBateman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is mostly looks good, just some minor word smithing on the docs change.

@openjdk openjdk Bot removed the csr Pull request needs approved CSR before integration label Apr 22, 2026
@openjdk openjdk Bot added the ready Pull request is ready to be integrated label Apr 23, 2026
@liach
Copy link
Copy Markdown
Member Author

liach commented Apr 23, 2026

/integrate

Thanks for the reviews!

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Apr 23, 2026

Going to push as commit cb8860a.
Since your change was applied there have been 16 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk Bot added the integrated Pull request has been integrated label Apr 23, 2026
@openjdk openjdk Bot closed this Apr 23, 2026
@openjdk openjdk Bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Apr 23, 2026
@openjdk
Copy link
Copy Markdown

openjdk Bot commented Apr 23, 2026

@liach Pushed as commit cb8860a.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler compiler-dev@openjdk.org core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

4 participants