Skip to content

8357063: Document preconditions for DecimalDigits methods #25246

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

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 is no longer ready for integration - check the PR body for details.

@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.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label May 15, 2025
@wenshao wenshao force-pushed the dec_unchecked_202505 branch from 792d16f to d40cad7 Compare May 15, 2025 07:39
@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.

* UTF-16 coder.
*
* @param i value to convert
* @param index next index, after the least significant digit
* @param buf target buffer, UTF16-coded.
* @return index of the most significant digit or minus sign, if present
*/
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.

wenshao and others added 8 commits May 17, 2025 00:00
Co-authored-by: Volkan Yazıcı <volkan.yazici@oracle.com>
Co-authored-by: Volkan Yazıcı <volkan.yazici@oracle.com>
Co-authored-by: Volkan Yazıcı <volkan.yazici@oracle.com>
Co-authored-by: Volkan Yazıcı <volkan.yazici@oracle.com>
Co-authored-by: Volkan Yazıcı <volkan.yazici@oracle.com>
Co-authored-by: Volkan Yazıcı <volkan.yazici@oracle.com>
Co-authored-by: Volkan Yazıcı <volkan.yazici@oracle.com>
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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
core-libs core-libs-dev@openjdk.org rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

4 participants