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

JDK-8321545: Override toString() for Format subclasses #17355

Conversation

justin-curtis-lu
Copy link
Member

@justin-curtis-lu justin-curtis-lu commented Jan 10, 2024

Please review this PR which implements toString() for the Format subclasses. Corresponding CSR: JDK-8323088

The general specification follows a template that provides the locale (if the class is localized) and any relevant patterns. The specification was intentionally kept minimal and deliberately worded as "for debugging".

An example of all the classes has output such as

CompactNumberFormat [locale: "English (United States)", decimal pattern: "foo#0.00#baz", compact patterns: "[, , , {one:0K other:0K}, {one:00K other:00K}, {one:000K other:000K}, {one:0M other:0M}, {one:00M other:00M}, {one:000M other:000M}, {one:0B other:0B}, {one:00B other:00B}, {one:000B other:000B}, {one:0T other:0T}, {one:00T other:00T}, {one:000T other:000T}]"]

DecimalFormat [locale: "English (United States)", pattern: "foo#0.00#baz"]

SimpleDateFormat [locale: "Chinese (China)", pattern: "EEE, MMM d, ''yy"]

ListFormat [locale: "English (United States)", start: "{0}, {1}", middle: "{0}, {1}", end: "{0}, and {1}", two: "{0} and {1}", three: "{0}, {1}, and {2}"]

MessageFormat [locale: "Chinese (China)", pattern: "foo {0}"]

ChoiceFormat [pattern: "0#foo"]

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-8323088 to be approved

Issues

  • JDK-8321545: Override toString() for Format subclasses (Enhancement - P4)
  • JDK-8323088: Override toString() for Format subclasses (CSR)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 17355

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 10, 2024

👋 Welcome back jlu! 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 the rfr Pull request is ready for review label Jan 10, 2024
@openjdk
Copy link

openjdk bot commented Jan 10, 2024

@justin-curtis-lu The following labels will be automatically applied to this pull request:

  • 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 core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org labels Jan 10, 2024
@mlbridge
Copy link

mlbridge bot commented Jan 10, 2024

Webrevs

@naotoj
Copy link
Member

naotoj commented Jan 11, 2024

I think test cases for these new overridden toString() methods would be helpful.

@justin-curtis-lu
Copy link
Member Author

I think test cases for these new overridden toString() methods would be helpful.

Added test cases for the new methods. Additionally, in the most recent commit, I swapped the placement of compact patterns with decimal pattern. As compact patterns is generally much longer, I felt it helped readability if decimal pattern came first.

Copy link
Member

@naotoj naotoj left a comment

Choose a reason for hiding this comment

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

Added tests look good.

return
"""
MessageFormat [locale: "%s", pattern: "%s"]
""".formatted(locale == null ? "None" : locale.getDisplayName(), toPattern());
Copy link
Member

Choose a reason for hiding this comment

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

I think printing null for locale == null is better here, as None is sort of ambiguous. Applies to SDF (and related tests) as well.

Copy link
Member

@naotoj naotoj left a comment

Choose a reason for hiding this comment

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

LGTM. The locale object could be passed to formatted() argument instead of the hard-coded "null", but that is ok

@openjdk
Copy link

openjdk bot commented Jan 12, 2024

@justin-curtis-lu 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:

8321545: Override toString() for Format subclasses

Reviewed-by: naoto, 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 13 new commits pushed to the master branch:

  • 8b9bf75: 8323515: Create test alias "all" for all test roots
  • 3d82363: 8300088: [IMPROVE] OPEN_MAX is no longer the max limit on macOS >= 10.6 for RLIMIT_NOFILE
  • 2a01c79: 8324513: Inline ContiguousSpace::object_iterate_from
  • fbaaac6: 8314164: java/net/HttpURLConnection/HttpURLConnectionExpectContinueTest.java fails intermittently in timeout
  • 791b427: 8323640: [TESTBUG]testMemoryFailCount in jdk/internal/platform/docker/TestDockerMemoryMetrics.java always fail because OOM killed
  • bcaad51: 8318228: RISC-V: C2 ConvF2HF
  • 5acd37f: 8324207: Serial: Remove Space::set_saved_mark_word
  • f5e6d11: 8324210: Serial: Remove unused methods in Generation
  • bcb340d: 8324286: Fix backsliding on use of nullptr instead of NULL
  • 3696765: 8323964: runtime/Thread/ThreadCountLimit.java fails intermittently on AIX
  • ... and 3 more: https://git.openjdk.org/jdk/compare/0d8543d6773a516dad54038070dce507179d0709...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 Jan 12, 2024
return
"""
MessageFormat [locale: "%s", pattern: "%s"]
""".formatted(locale == null ? "null" : locale.getDisplayName(), toPattern());
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be more accurate if when locale ==null that null was not quoted in the string.
Seeing "null" would imply that the displayName of the locale was "null", when it was null.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi Roger, addressed in 70e0a17; would like to confirm the update is okay with you before integration.

return
"""
MessageFormat [locale: %s, pattern: "%s"]
""".formatted(locale == null ? null : '"'+locale.getDisplayName()+'"', toPattern());
Copy link
Contributor

Choose a reason for hiding this comment

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

Style wise, operators (like "+") should have spaces around them.

return
"""
SimpleDateFormat [locale: %s, pattern: "%s"]
""".formatted(locale == null ? null : '"'+locale.getDisplayName()+'"', toPattern());
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto, add spaces around +.

@Test
public void oddValueTest() {
String expectedStr =
"SimpleDateFormat [locale: \""+Locale.getDefault().getDisplayName()+"\", pattern: \"MMM d, y\"]\n";
Copy link
Contributor

Choose a reason for hiding this comment

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

Add spaces around operator +

@justin-curtis-lu
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Jan 23, 2024

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

  • edfee7f: 8323546: Cleanup jcmd docs for Compiler.perfmap and VM.cds filename parameter
  • 8b9bf75: 8323515: Create test alias "all" for all test roots
  • 3d82363: 8300088: [IMPROVE] OPEN_MAX is no longer the max limit on macOS >= 10.6 for RLIMIT_NOFILE
  • 2a01c79: 8324513: Inline ContiguousSpace::object_iterate_from
  • fbaaac6: 8314164: java/net/HttpURLConnection/HttpURLConnectionExpectContinueTest.java fails intermittently in timeout
  • 791b427: 8323640: [TESTBUG]testMemoryFailCount in jdk/internal/platform/docker/TestDockerMemoryMetrics.java always fail because OOM killed
  • bcaad51: 8318228: RISC-V: C2 ConvF2HF
  • 5acd37f: 8324207: Serial: Remove Space::set_saved_mark_word
  • f5e6d11: 8324210: Serial: Remove unused methods in Generation
  • bcb340d: 8324286: Fix backsliding on use of nullptr instead of NULL
  • ... and 4 more: https://git.openjdk.org/jdk/compare/0d8543d6773a516dad54038070dce507179d0709...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jan 23, 2024

@justin-curtis-lu Pushed as commit 96607df.

💡 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