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-8316435: sun.util.calendar.CalendarSystem subclassing should be restricted #15803

Conversation

justin-curtis-lu
Copy link
Member

@justin-curtis-lu justin-curtis-lu commented Sep 18, 2023

Please review this PR which restricts sub-classing of the internal calendar system in sun.util.calendar to only the existing implementations. Drive by cleanup included.

As the implementation is long-standing and complete with no intent for future sub-classing, the CalendarSystem should be made sealed. Modifiers adjusted accordingly (JulianCalendar.Date must now have package visibility).

This system has the following structure,

CalendarSystem extended by AbstractCalendar extended by BaseCalendar extended by
(Gregorian, JulianCalendar, LocalGregorianCalendar)

CalendarDate extended by BaseCalendar.Date extended by
(Gregorian.Date, ImmutableGregorianDate, JulianCalendar.Date, LocalGregorianCalendar.Date)

Additionally, CalendarUtils was made final, as it is a utility class composed of static util methods.


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

Issue

  • JDK-8316435: sun.util.calendar.CalendarSystem subclassing should be restricted (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 15803

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 18, 2023

👋 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 Sep 18, 2023
@openjdk
Copy link

openjdk bot commented Sep 18, 2023

@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 Sep 18, 2023
@mlbridge
Copy link

mlbridge bot commented Sep 18, 2023

Webrevs

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.

Looks good overall.

public class CalendarUtils {
public final class CalendarUtils {

private CalendarUtils() {}
Copy link
Member

Choose a reason for hiding this comment

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

It may be obvious, but adding a comment would be helpful, i.e., no instance may be created.

static class Date extends BaseCalendar.Date {
protected Date() {
static final class Date extends BaseCalendar.Date {
Date() {
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 removing protected from the final class methods is fine. Adding @Override may be helpful.

long z = mod(x, y);
return (z == 0) ? y : z;
}

/**
* Mimics sprintf(buf, "%0*d", decaimal, width).
*/
public static final StringBuilder sprintf0d(StringBuilder sb, int value, int width) {
public static StringBuilder sprintf0d(StringBuilder sb, int value, int width) {
Copy link
Member

Choose a reason for hiding this comment

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

Can this (and the following overload) method be eliminated? No need to mimic sprintf here, but using String.format/formatted should suffice?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for reviewing, replaced the two methods with Formatter (there are occurrences in test as well)

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I was not aware that the utility methods were used in Date.toString(). I will have to take my suggestion back for performance reasons (assuming the existing implementation is faster). Sorry for not noticing that beforehand.

@srl295
Copy link
Member

srl295 commented Sep 19, 2023

I added a question on https://bugs.openjdk.org/browse/JDK-8316435 as to the effect on future calendar systems.

@openjdk
Copy link

openjdk bot commented Sep 19, 2023

@justin-curtis-lu this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout JDK-8316435-seal-sun.util.calendar
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label Sep 19, 2023
@openjdk openjdk bot removed the merge-conflict Pull request has merge conflict with target branch label Sep 19, 2023
@@ -59,7 +59,8 @@
* @author Masayoshi Okutsu
* @since 1.5
*/
public abstract class CalendarDate implements Cloneable {
public sealed abstract class CalendarDate implements Cloneable
permits BaseCalendar.Date {
Copy link
Member

Choose a reason for hiding this comment

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

Can we just merge CalendarDate and BaseCalendar.Date to be the one class?
I think it will greatly simplify the code.

Copy link
Member

@naotoj naotoj Sep 20, 2023

Choose a reason for hiding this comment

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

BaseCalendar is for Gregorian based calendars, so its Date class also represents dates for those calendars, while CalendarDate is an abstract class for all calendar implementations. So I don't think merging them is the right direction.

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

@openjdk
Copy link

openjdk bot commented Sep 20, 2023

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

8316435: sun.util.calendar.CalendarSystem subclassing should be restricted

Reviewed-by: naoto

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

  • a021dbc: 8316149: Open source several Swing JTree JViewport KeyboardManager tests
  • 455cfae: 8315880: change LockingMode default from LM_LEGACY to LM_LIGHTWEIGHT
  • 9e00949: 8316427: Duplicated code for {obj,type}ArrayKlass::array_klass
  • c43ebd3: 8315981: Opensource five more random Swing tests
  • e30e356: 8316461: Fix: make test outputs TEST SUCCESS after unsuccessful exit
  • 242eeae: 8286757: adlc tries to build with /pathmap but without /experimental:deterministic
  • b275bdd: 8308995: Update Network IO JFR events to be static mirror events
  • e1870d3: 8316411: compiler/compilercontrol/TestConflictInlineCommands.java fails intermittent with force inline by CompileCommand missing
  • ec74194: 8316546: Backout JDK-8315932: runtime/InvocationTests spend a lot of time on dependency verification
  • 2568188: 8316547: Use JUnit.dir jtreg property with jpackage JUnit tests
  • ... and 27 more: https://git.openjdk.org/jdk/compare/373e37bf13df654ba40c0bd9fcf345215be4eafb...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 20, 2023
@justin-curtis-lu
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Sep 21, 2023

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

  • 1100dbc: 8316695: ProblemList serviceability/jvmti/RedefineClasses/RedefineLeakThrowable.java
  • d3e8218: 8316306: Open source and convert manual Swing test
  • 4e57177: 8316383: NullPointerException in AbstractSAXParser after JDK-8306632
  • 3b397c8: 8315965: Open source various AWT applet tests
  • c698b45: 8313229: DHEKeySizing.java should be modified to use TLS versions TLSv1, TLSv1.1, TLSv1.2
  • 015f6f5: 8315771: [JVMCI] Resolution of bootstrap methods with int[] static arguments
  • 83b01cf: 8311922: [macOS] right-Option key fails to generate release event
  • 542b300: 8315954: getArgumentValues002.java fails on Graal
  • 0637900: 8316433: net.dll should delay load winhttp.dll
  • 90bcdbd: 8316581: Improve performance of Symbol::print_value_on()
  • ... and 61 more: https://git.openjdk.org/jdk/compare/373e37bf13df654ba40c0bd9fcf345215be4eafb...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Sep 21, 2023

@justin-curtis-lu Pushed as commit 496264c.

💡 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
Development

Successfully merging this pull request may close these issues.

4 participants