Skip to content

Conversation

wenshao
Copy link
Contributor

@wenshao wenshao commented May 15, 2025

Similar to PR #24982
Document preconditions on certain DecimalDigits methods that use operations either unsafe and/or without range checks.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8357063: Document preconditions for DecimalDigits methods (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25246

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented May 15, 2025

👋 Welcome back swen! 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

openjdk bot commented May 15, 2025

@wenshao 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:

8357063: Document preconditions for DecimalDigits methods

Reviewed-by: vyazici, liach, rriggs

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 56 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
Copy link

openjdk bot commented May 15, 2025

@wenshao The following label will be automatically applied to this pull request:

  • core-libs

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

@wenshao wenshao force-pushed the dec_unchecked_202505 branch from d40cad7 to 66f71c5 Compare May 15, 2025 07:41
@wenshao wenshao marked this pull request as ready for review May 15, 2025 16:41
@wenshao wenshao changed the title Document preconditions for DecimalDigits methods 8357063: Document preconditions for DecimalDigits methods May 15, 2025
@openjdk openjdk bot added the rfr Pull request is ready for review label May 15, 2025
@mlbridge
Copy link

mlbridge bot commented May 15, 2025

Webrevs

@rgiulietti
Copy link
Contributor

@wenshao I understand this is a kind of followup of #24982, but why this title? It seems just renaming some methods with more speaking names.

@wenshao
Copy link
Contributor Author

wenshao commented May 15, 2025

@wenshao I understand this is a kind of followup of #24982, but why this title? It seems just renaming some methods with more speaking names.

Yes, it is just a renaming of some methods, the title is followup #24982, does the same thing, so uses the same title

@rgiulietti
Copy link
Contributor

The renaming is nice and useful.
But #24982, in addition to renaming, emphasizes the expectations about correct usage with bold WARNINGs in the JavaDoc. That's the "document preconditions" in the title.
Adding similar warnings in the JavaDoc, rather than in plain comments in the methods, would be clearer.

*/
public static int getCharsUTF16(long i, int index, byte[] buf) {
public static int uncheckedGetCharsUTF16(long i, int index, byte[] buf) {
// Used by trusted callers. Assumes all necessary bounds checks have been done by the caller.
Copy link
Contributor

@vy vy May 16, 2025

Choose a reason for hiding this comment

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

Regarding all methods that are prefixed with unchecked in this PR, IMHO:

  1. Precondition warnings should better be moved to the JavaDoc (ala 8353197: Document preconditions for JavaLangAccess methods #24982)
  2. We shall also consider implementing these preconditions using assert statements

Copy link
Contributor

@vy vy left a comment

Choose a reason for hiding this comment

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

@wenshao, thanks for the kind effort – dropped suggestions to match the messages with the ones in JLA.

I prefer all1 public, unchecked-prefixed DecimalDigits methods to start with a sufficient assert preamble, to fail as early as possible. Though I don't want to create redundant extra work, hence double checking: @jaikiran, @minborg, @liach, WDYT?

1 Currently, only two private methods are introduced asserts, which are fine.

@liach
Copy link
Member

liach commented May 16, 2025

Re assert preamble for public methods: Unfortunately this is not possible. The algorithm requires the chars to be written on demand, and it is very costly to precompute the length, aside from the fact that you can easily mess up on precomputation. The uncheckedness is from the 2 private methods, so I think safeguarding the 2 private methods with assertions is sufficient.

Copy link
Member

@liach liach left a comment

Choose a reason for hiding this comment

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

This version looks good to me. Please wait for a second confirmation. (Allowing authors like @vy to review too)

/reviewers 2

@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 16, 2025
@openjdk
Copy link

openjdk bot commented May 16, 2025

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

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label May 16, 2025
@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 19, 2025
Copy link
Contributor

@RogerRiggs RogerRiggs left a comment

Choose a reason for hiding this comment

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

Useful renames and comment placement improvements. lgtm.

* @return index of the most significant digit or minus sign, if present
*/
public static int getChars(long i, int index, char[] buf) {
// Used by trusted callers. Assumes all necessary bounds checks have been done by the caller.
Copy link
Member

Choose a reason for hiding this comment

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

Hello Shaojin, I think this was a misplaced comment previously. Looking at the implementation of this method, there's no "unsafe" access happening in this method's implementation. It ends up calling putChar which does a Java style array access and thus is backed by the language's bounds checking.

Removing this comment I believe is the right thing. Having said that, I am unsure the javadoc comment of this method should refer to DecimalDigits#uncheckedGetCharsUTF16 because that is confusing and misleading.

Should we change the javadoc text of this method to:

Places characters representing the long i into the character array buf. The characters are placed into the buffer backwards starting with the least significant digit at the specified index (exclusive), and working backwards from there.

Would that accurately describe what this method's implementation currently does?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method has the same algorithm as uncheckedGetCharsUTF16, the only difference is the safe array access of char[] and the unsafe access of byte[] by uncheckedPutPairUTF16.

This method was also copied from uncheckedGetCharsUTF16 and then modified when the code was written, so I think the reference here is OK.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/integrate

@wenshao
Copy link
Contributor Author

wenshao commented May 21, 2025

/integrate

@openjdk
Copy link

openjdk bot commented May 21, 2025

Going to push as commit 07871cd.
Since your change was applied there have been 103 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 May 21, 2025
@openjdk openjdk bot closed this May 21, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels May 21, 2025
@openjdk
Copy link

openjdk bot commented May 21, 2025

@wenshao Pushed as commit 07871cd.

💡 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
core-libs [email protected] integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

6 participants