Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

8291660: Grapheme support in BreakIterator #9991

Closed
wants to merge 10 commits into from

Conversation

naotoj
Copy link
Member

@naotoj naotoj commented Aug 23, 2022

This is to enhance the character break analysis in java.text.BreakIterator to conform to the extended grapheme cluster boundaries defined in https://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries. A corresponding CSR has also been drafted, as there will be behavioral changes with this modification.


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 a CSR request to be approved

Issues

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 9991

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

Using diff file

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

@naotoj
Copy link
Member Author

naotoj commented Aug 23, 2022

/csr

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 23, 2022

👋 Welcome back naoto! 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 openjdk bot added rfr Pull request is ready for review csr Pull request needs approved CSR before integration labels Aug 23, 2022
@openjdk
Copy link

openjdk bot commented Aug 23, 2022

@naotoj an approved CSR request is already required for this pull request.

@openjdk
Copy link

openjdk bot commented Aug 23, 2022

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

  • build
  • core-libs
  • i18n

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 build build-dev@openjdk.org core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org labels Aug 23, 2022
@mlbridge
Copy link

mlbridge bot commented Aug 23, 2022

Webrevs

@magicus
Copy link
Member

magicus commented Aug 24, 2022

/label -build

@openjdk openjdk bot removed the build build-dev@openjdk.org label Aug 24, 2022
@openjdk
Copy link

openjdk bot commented Aug 24, 2022

@magicus
The build label was successfully removed.

* @build java.base/java.util.regex.GraphemeTestAccessor
* @run testng GraphemeTest
* @compile --add-exports java.base/jdk.internal.util.regex=ALL-UNNAMED GraphemeTest.java
* @run testng/othervm --add-exports java.base/jdk.internal.util.regex=ALL-UNNAMED --add-opens java.base/jdk.internal.util.regex=ALL-UNNAMED GraphemeTest
Copy link
Member

@stuart-marks stuart-marks Aug 25, 2022

Choose a reason for hiding this comment

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

Can you use the @modules directive to export+open the internal module to the test?

Copy link
Member Author

@naotoj naotoj Aug 25, 2022

Choose a reason for hiding this comment

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

Good point. Will use @modules tag.

boundaryIndex = IntStream.range(0, boundaries.size())
.filter(i -> boundaries.get(i) > offset)
.findFirst()
.orElse(boundaries.size() - 1);
Copy link
Member

@stuart-marks stuart-marks Aug 25, 2022

Choose a reason for hiding this comment

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

Is it worth trying to use Collections.binarySearch() here? I think the boundaries list is in ascending sorted order, so you might be able to drop in a binarySearch() call directly. (Need to be a bit careful with negative return values.)

Copy link
Member Author

@naotoj naotoj Aug 25, 2022

Choose a reason for hiding this comment

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

Will replace this with Collections.binarySearch().

@stuart-marks
Copy link
Member

stuart-marks commented Aug 25, 2022

I took a quick look. Overall looks reasonable. How much scrutiny did you need?

Also, nice use of method handles.

Might be helpful to provide an example of the behavior change in the CSR.

This is probably also worth a release note documenting the behavior change and showing an example.

@naotoj
Copy link
Member Author

naotoj commented Aug 25, 2022

Thanks, Stuart. I will update the CSR as you suggested.
I found a couple of failures with the JCK tests. Will update the PR along with your suggestions.

@naotoj
Copy link
Member Author

naotoj commented Aug 26, 2022

Modified the fix according to suggestions. Also, the CSR has been updated and a release note has been drafted.

* For more detail, refer to
* <a href="https://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries">
* Grapheme Cluster Boundaries</a> section in the Unicode Standard Annex #29.
*
Copy link
Member

@stuart-marks stuart-marks Aug 26, 2022

Choose a reason for hiding this comment

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

I would say this is an @implSpec instead of an @implNote because we want applications to be able to rely on this behavior if they're using the default implementation. Also please make corresponding update to the CSR.

Copy link
Member Author

@naotoj naotoj Aug 26, 2022

Choose a reason for hiding this comment

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

Fixed

@openjdk openjdk bot removed the csr Pull request needs approved CSR before integration label Sep 1, 2022
static int nextBoundary(CharSequence src, int off, int limit) {
Objects.checkFromToIndex(off, limit, src.length());
public static int nextBoundary(CharSequence src, int off, int limit) {
Objects.checkFromToIndex(0, limit - off, src.length());
Copy link
Member

@stuart-marks stuart-marks Sep 7, 2022

Choose a reason for hiding this comment

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

Is this right? The old code's use of checkFromToIndex method seems to be the right way to check that off and limit are a valid from-to range within [0, src.length). The new code subtracts off from both args but the arithmetic seems to allow for some errors. For example, depending on the value of limit, this might permit off to be a small negative number.

Copy link
Member Author

@naotoj naotoj Sep 8, 2022

Choose a reason for hiding this comment

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

Thanks for the catch! Yes, this was a leftover before I fixed a couple of JCK failures which correctly fixed edge cases. Reverted the change.

CHARACTER_INDEX,
"CharacterData",
"CharacterDictionary");
return new GraphemeBreakIterator();
}
Copy link
Member

@stuart-marks stuart-marks Sep 7, 2022

Choose a reason for hiding this comment

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

It looks like there is some kind of table Since CHARACTER_INDEX is no longer used, does it mean there is now dead code for the CHARACTER break iterator class, and dead resources for CharacterData and CharacterDictionary? Should this be removed? Or maybe this is all in each locale or something and should be cleaned up later?

Copy link
Member Author

@naotoj naotoj Sep 8, 2022

Choose a reason for hiding this comment

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

Right. Removed the now-dead code.

Copy link
Member

@stuart-marks stuart-marks left a comment

Updates look good, assuming all the tests pass.

@openjdk
Copy link

openjdk bot commented Sep 9, 2022

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

8291660: Grapheme support in BreakIterator

Reviewed-by: smarks

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 28 new commits pushed to the master branch:

  • a14c3a4: 8288933: Improve the implementation of Double/Float.isInfinite
  • 00befdd: 8292675: Add identity transformation for removing redundant AndV/OrV nodes
  • 7169ee5: 8293477: IGV: Upgrade to Netbeans Platform 15
  • 3dd94f3: 8292671: Hotspot Style Guide should allow covariant returns
  • 9d6b028: 8234315: GTK LAF does not gray out disabled JMenu
  • 812d805: 6447816: Provider filtering (getProviders) is not working with OR'd conditions
  • 43e191d: 8293524: RISC-V: Use macro-assembler functions as appropriate
  • 14eb5ad: 8291753: Add JFR event for GC CPU Time
  • 30d4145: 8293230: x86_64: Move AES and GHASH stub definitions into separate source files
  • 4c5501c: 8293548: ProblemList sun/management/jmxremote/bootstrap/RmiBootstrapTest.java#id1 on linux-x64
  • ... and 18 more: https://git.openjdk.org/jdk/compare/32c7b6283daf6f3876ff62693d5a0cb7c4af4232...master

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 the ready Pull request is ready to be integrated label Sep 9, 2022
@naotoj
Copy link
Member Author

naotoj commented Sep 9, 2022

/integrate

@openjdk
Copy link

openjdk bot commented Sep 9, 2022

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

  • a14c3a4: 8288933: Improve the implementation of Double/Float.isInfinite
  • 00befdd: 8292675: Add identity transformation for removing redundant AndV/OrV nodes
  • 7169ee5: 8293477: IGV: Upgrade to Netbeans Platform 15
  • 3dd94f3: 8292671: Hotspot Style Guide should allow covariant returns
  • 9d6b028: 8234315: GTK LAF does not gray out disabled JMenu
  • 812d805: 6447816: Provider filtering (getProviders) is not working with OR'd conditions
  • 43e191d: 8293524: RISC-V: Use macro-assembler functions as appropriate
  • 14eb5ad: 8291753: Add JFR event for GC CPU Time
  • 30d4145: 8293230: x86_64: Move AES and GHASH stub definitions into separate source files
  • 4c5501c: 8293548: ProblemList sun/management/jmxremote/bootstrap/RmiBootstrapTest.java#id1 on linux-x64
  • ... and 18 more: https://git.openjdk.org/jdk/compare/32c7b6283daf6f3876ff62693d5a0cb7c4af4232...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Sep 9, 2022
@openjdk openjdk bot closed this Sep 9, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 9, 2022
@openjdk
Copy link

openjdk bot commented Sep 9, 2022

@naotoj Pushed as commit b8598b0.

💡 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 core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org integrated Pull request has been integrated
3 participants