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

8313813: Field sun.util.calendar.CalendarDate#forceStandardTime is never set #15726

Conversation

justin-curtis-lu
Copy link
Member

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

Please review this PR which is a continuation of JDK-6453901 to remove unused code from the sun.util.Calendar classes.

forceStandardTime is always false.

In addition, locale is never by used by CalendarDate or any inheritors and can be removed.

As a result, ImmutableGregorianDate no longer needs to override the setLocale method and throw UnsupportedOperationException.


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-8313813: Field sun.util.calendar.CalendarDate#forceStandardTime is never set (Bug - P5)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 15726

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 13, 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 13, 2023
@openjdk
Copy link

openjdk bot commented Sep 13, 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 13, 2023
@mlbridge
Copy link

mlbridge bot commented Sep 13, 2023

Webrevs

@@ -295,7 +291,7 @@ public boolean isNormalized() {


public boolean isStandardTime() {
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 remove(inline) this method?

@@ -167,29 +167,16 @@ public long getTime(CalendarDate date) {
}
// adjust time zone and daylight saving
int[] offsets = new int[2];
if (date.isStandardTime()) {
Copy link
Member Author

@justin-curtis-lu justin-curtis-lu Sep 13, 2023

Choose a reason for hiding this comment

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

This seems a little suspicious considering isStandardTime() is always false.

However, at this point, there shouldn't be any behavioral changes probably.

@@ -167,29 +167,16 @@ public long getTime(CalendarDate date) {
}
// adjust time zone and daylight saving
int[] offsets = new int[2];
Copy link
Member

Choose a reason for hiding this comment

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

Let's move array allocation only to if (zi instanceof ZoneInfo) { case

// 3) 1:30am during ending-DST transition is interpreted
// as 1:30am DT/0:30am ST (before transition)
if (zi instanceof ZoneInfo) {
zoneOffset = ((ZoneInfo)zi).getOffsetsByWall(ms, offsets);
Copy link
Member

Choose a reason for hiding this comment

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

let's use pattern matching for instanceof

// 3) 1:30am during ending-DST transition is interpreted
// as 1:30am DT/0:30am ST (before transition)
if (zi instanceof ZoneInfo zInfo) {
// Offset value adjusts accordingly depending on DST status of date
Copy link
Member Author

Choose a reason for hiding this comment

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

Historically, this if else has not been touched since the introduction of the class.

The original code has a structure that one can presume follows the logic, if isStandardTime(), get a standard offset, otherwise get a day light saving offset. This is not the case.

The code within the else statement is able to retrieve the correct offset if the date is in standard or in day light saving time (not just a day light saving offset, as the original code would imply). Consider the following example,

// Where ms is calculated from the date: LA time zone at 3-13-2016 at 4 AM (daylight saving)
zoneOffset = zInfo.getOffsetsByWall(ms, new int[2]); 
// returns the adjusted offset, -25200000 (7 hours)

// Where ms is calculated from the date: LA time zone at 1-13-2016 at 4 AM (standard)
zoneOffset = zInfo.getOffsetsByWall(ms, new int[2]); 
// returns the standard offset, -28800000 (8 hours)

Removing this code is not only safe because isStandardTime() is always false

  • tiers 1-3 clean
  • breakpoint within the original if never breaks execution for JDK Calendar tests

But we can also feel that the change is not suspicious since the code within the else block can produce a standard or daylight offset.

Copy link
Member

Choose a reason for hiding this comment

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

I suspect that the original design is to have this overridden by possible subclasses if needed, but none has done so far (and I don't think it ever will). So I think it is safe (and less complex) to remove these unused codes.

// 3) 1:30am during ending-DST transition is interpreted
// as 1:30am DT/0:30am ST (before transition)
if (zi instanceof ZoneInfo zInfo) {
// Offset value adjusts accordingly depending on DST status of 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 suspect that the original design is to have this overridden by possible subclasses if needed, but none has done so far (and I don't think it ever will). So I think it is safe (and less complex) to remove these unused codes.

zoneOffset = zi.getOffset(ms - zi.getRawOffset());
}
// 1) 2:30am during starting-DST transition is
// intrepreted as 3:30am DT
Copy link
Member

Choose a reason for hiding this comment

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

Not your change, but I think this is a typo of interpreted

@openjdk
Copy link

openjdk bot commented Sep 15, 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:

8313813: Field sun.util.calendar.CalendarDate#forceStandardTime is never set

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

  • 4b8f5d0: 8316273: JDK-8315818 broke JVMCIPrintProperties on libgraal
  • e624198: 8316387: Exclude more failing multicast tests on AIX after JDK-8315651
  • c92bdb0: 8316187: Modernize examples in StringTokenizer and {Date,Number}Format
  • 8f46abc: 8315889: Open source several Swing HTMLDocument related tests
  • 0050447: 8316148: Remove sun/tools/jhsdb/JStackStressTest.java from problem list
  • 149acd1: 8316207: Fix typos in java.io.StreamTokenizer
  • dc5ca1d: 8316031: SSLFlowDelegate should not log from synchronized block
  • 8dfde28: 8315485: (fs) Move java/nio/file/Path/Misc.java tests into java/nio/file/Path/PathOps.java
  • 3c743cf: 8312126: NullPointerException in CertStore.getCRLs after 8297955
  • bd26813: 8316295: Serial: Remove empty Generation::promotion_failure_occurred
  • ... and 78 more: https://git.openjdk.org/jdk/compare/fda142ff6cfefa12ec1ea4d4eb48b3c1b285bc04...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 15, 2023
Comment on lines -157 to -160
protected void setLocale(Locale loc) {
unsupported();
}

Copy link
Member

Choose a reason for hiding this comment

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

This removal does not look right. The class claims immutable, and yet it is now allowing setting the locale.

Copy link
Member

Choose a reason for hiding this comment

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

There is no setLocale method in the base class anymore. So, it's not possible to set locale in any classes which extend BaseCalendar.Date, including ImmutableGregorianDate

Copy link
Member

Choose a reason for hiding this comment

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

It is ok then. (missed the removal of the method in the abstract class). Now come to think of it, I would like them to be sealed to make sure they are not randomly subclassed, but that clean-up is for another day.

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.

I have to retract the PR approval for the said reason

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Sep 15, 2023
Comment on lines -157 to -160
protected void setLocale(Locale loc) {
unsupported();
}

Copy link
Member

Choose a reason for hiding this comment

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

It is ok then. (missed the removal of the method in the abstract class). Now come to think of it, I would like them to be sealed to make sure they are not randomly subclassed, but that clean-up is for another day.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 16, 2023
@justin-curtis-lu
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Sep 18, 2023

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

  • 5308bbb: 8246280: Refine API to model sealed classes and interfaces in javax.lang.model
  • dcea9bf: 8301247: JPackage app-image exe launches multiple exe's in JDK 17+
  • 1b104b6: 8314909: tools/jpackage/windows/Win8282351Test.java fails with java.lang.AssertionError: Expected [0]. Actual [1618]:
  • 4421951: 8316142: Enable parallelism in vmTestbase/nsk/monitoring/stress/lowmem tests
  • f09b7af: 8311220: Optimization for StringLatin UpperLower
  • 2e2d49c: 8316400: Exclude jdk/jfr/event/runtime/TestResidentSetSizeEvent.java on AIX
  • bf9d1e2: 8316399: Exclude java/net/MulticastSocket/Promiscuous.java on AIX
  • 21c2dac: 8315706: com/sun/tools/attach/warnings/DynamicLoadWarningTest.java real fix for failure on AIX
  • ecce2af: 8316357: Serial: Remove unused GenCollectedHeap::space_containing
  • 3828dc9: 8314236: Overflow in Collections.rotate
  • ... and 93 more: https://git.openjdk.org/jdk/compare/fda142ff6cfefa12ec1ea4d4eb48b3c1b285bc04...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Sep 18, 2023

@justin-curtis-lu Pushed as commit 373e37b.

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

3 participants