Skip to content

8347955: TimeZone methods to stream the available timezone IDs#23251

Closed
justin-curtis-lu wants to merge 6 commits intoopenjdk:masterfrom
justin-curtis-lu:JDK-8347955-tz-IDs-stream
Closed

8347955: TimeZone methods to stream the available timezone IDs#23251
justin-curtis-lu wants to merge 6 commits intoopenjdk:masterfrom
justin-curtis-lu:JDK-8347955-tz-IDs-stream

Conversation

@justin-curtis-lu
Copy link
Member

@justin-curtis-lu justin-curtis-lu commented Jan 23, 2025

Please review this PR and CSR which add a pair of methods to java.util.TimeZone that return a stream of the available IDs. See the CSR for the motivation.

A number of existing tests are modified to use the new methods. See test/jdk/java/util/TimeZone/AvailableIDsTest.java which tests the new 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
  • Change requires CSR request JDK-8348325 to be approved

Issues

  • JDK-8347955: TimeZone methods to stream the available timezone IDs (Enhancement - P4)
  • JDK-8348325: TimeZone methods to stream the available timezone IDs (CSR)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 23251

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 23, 2025

👋 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
Copy link

openjdk bot commented Jan 23, 2025

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

8347955: TimeZone methods to stream the available timezone IDs

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

  • 21feef3: 8348239: SA does not know about DeoptimizeObjectsALotThread
  • 8cc1304: 8287788: Implement a better allocator for downcalls
  • 039e73f: 8346736: Java Security Standard Algorithm Names spec should include key algorithm names
  • aba60a9: 8189441: Define algorithm names for keys derived from KeyAgreement
  • 03106eb: 8344119: CUPSPrinter does not respect PostScript printer definition specification in case of reading ImageableArea values from PPD files
  • ad01dfb: 8346920: Serial: Support allocation in old generation when heap is almost full
  • 1d8ccb8: 8342465: Improve API documentation for java.lang.classfile
  • 7d6055a: 8348429: Update cross-compilation devkits to Fedora 41/gcc 13.2
  • f1e0797: 8348586: Optionally silence make warnings about non-control variables
  • ffeb9b5: 8342807: Update links in java.base to use https://
  • ... and 57 more: https://git.openjdk.org/jdk/compare/b720517cb33c2119ec6ed85504bce321de748228...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 changed the title JDK-8347955: TimeZone methods to stream the available timezone IDs 8347955: TimeZone methods to stream the available timezone IDs Jan 23, 2025
@openjdk openjdk bot added csr Pull request needs approved CSR before integration rfr Pull request is ready for review labels Jan 23, 2025
@openjdk
Copy link

openjdk bot commented Jan 23, 2025

@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 23, 2025
@mlbridge
Copy link

mlbridge bot commented Jan 23, 2025

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. Some files need copyright year bump

* not create a copy of the {@code TimeZone} IDs array.
*
* @param rawOffset the given time zone GMT offset in milliseconds.
* @return an array of IDs, where the time zone for that ID has
Copy link
Member

Choose a reason for hiding this comment

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

array -> stream

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 the catch. Fixed this and bumped those Zone* file copyright years in 48956fd. I double checked that all the test files have 2025 copyright years.

// specify it. Keep the same behavior for better
// compatibility.
String[] list = ids.toArray(new String[ids.size()]);
String[] list = ids.toArray(new String[0]);
Copy link
Member

Choose a reason for hiding this comment

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

Why is this change? Since the array has correct size, no extra array allocation is needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Regarding the switch from toArray(new T[size]) to toArray(new T[0]), based off https://shipilev.net/blog/2016/arrays-wisdom-ancients/#_conclusion, the JVM performs the latter faster. I believe the article data/results still hold true now.

public static Stream<String> zoneIds(int rawOffset) {
return zoneIds()
.filter(id -> getZoneInfo(id).getRawOffset() == rawOffset)
.sorted(); // Sort the IDs, see getZoneIds(int)
Copy link
Member

Choose a reason for hiding this comment

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

This is interesting. one with rawOffset is soreted, but the other is not. It is inconsistent but probably we should align as you did here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Noticed that too. There is also the argument that since these stream methods are new, we can leave it un-sorted but we would have to specify the deviation. Although I agree it is best to align for consistency.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually I'm wondering if we should specify these rawOffset methods with an @implNote that states they are sorted.

Copy link
Member

Choose a reason for hiding this comment

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

I'd rather not. If we did, users would wonder why no-arg return is not sorted, which might be a mere overlook (and if we sort it, it would be costly (num of tzids are not small))

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair enough.

* @see #getAvailableIDs(int)
* @since 25
*/
public static synchronized Stream<String> availableIDs(int rawOffset) {
Copy link
Member

Choose a reason for hiding this comment

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

Why are these new methods synchronized? I think the streams and the spliterators are late-binding, so the synchronization does not synchronize the access to the underlying arrays. synchronized modifier also does not appear in Javadoc and is not part of the API surface, so it can be safely removed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, it can be removed. Actually, I think getAvailableIDs() and getAvailableIDs(int) also do not need to be synchronized. The internal IDs are eagerly initialized in the static block of ZoneInfoFile.java and are effectively final and not modified.

Copy link
Member

Choose a reason for hiding this comment

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

Yep; their synchronized are incorrect. The object monitor lock should have been on ZoneInfoFile.class to be effective.

Copy link
Member

Choose a reason for hiding this comment

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

Related PR waiting for review - #17441

@openjdk openjdk bot removed the csr Pull request needs approved CSR before integration label Jan 24, 2025
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 openjdk bot added the ready Pull request is ready to be integrated label Jan 24, 2025
Copy link
Contributor

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

@justin-curtis-lu
Copy link
Member Author

Thanks for the reviews.
/integrate

@openjdk
Copy link

openjdk bot commented Jan 28, 2025

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

  • 1efae9a: 8348888: tier1 closed build failure on Windows after JDK-8348348
  • c018a60: 8344637: Fix Page8 of manual test java/awt/print/PrinterJob/PrintTextTest.java on Linux and Windows
  • c3c3888: 8336760: [JVMCI] -XX:+PrintCompilation should also print "hosted" JVMCI compilations
  • 9f4d3de: 8347718: Unexpected NullPointerException in C2 compiled code due to ReduceAllocationMerges
  • a224f12: 8348205: Improve cutover time selection when building available currencies set
  • 8103256: 8348348: Remove unnecessary #ifdef STATIC_BUILD around DEF_STATIC_JNI_OnLoad from zip_util.c
  • fb066ca: 8347272: [ubsan] JvmLauncher.cpp:262:52: runtime error: applying non-zero offset 40 to null pointer
  • 5fec999: 8339668: Parallel: Adopt PartialArrayState to consolidate marking stack in Full GC
  • 2bef5b4: 8348323: Corrupted timezone string in JVM crash log
  • 3a8680e: 8347058: When automatically translating the page to pt-br, all CSS styling disappears
  • ... and 74 more: https://git.openjdk.org/jdk/compare/b720517cb33c2119ec6ed85504bce321de748228...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jan 28, 2025

@justin-curtis-lu Pushed as commit 3a564ed.

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

5 participants