Skip to content

8179918: EnumSet spliterator should report SORTED, ORDERED, NONNULL#28568

Closed
kilink wants to merge 6 commits intoopenjdk:masterfrom
kilink:enum-spliterator-characteristics
Closed

8179918: EnumSet spliterator should report SORTED, ORDERED, NONNULL#28568
kilink wants to merge 6 commits intoopenjdk:masterfrom
kilink:enum-spliterator-characteristics

Conversation

@kilink
Copy link
Contributor

@kilink kilink commented Nov 29, 2025

I noticed that the Spliterator for EnumSet does not report SORTED, ORDERED, or NONNULL characteristics, all of which are inherent to API of EnumSet. I found there's an existing ticket for this as well.

The ticket also mentions optimized forEach, etc, which I presume means avoiding the default implementation that uses the iterator and just iterating over the bitset directly; I can add that here or perhaps in a follow up if it's still deemed worthwhile.


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-8179918: EnumSet spliterator should report SORTED, ORDERED, NONNULL (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28568

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 29, 2025

👋 Welcome back kilink! 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 Nov 29, 2025

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

8179918: EnumSet spliterator should report SORTED, ORDERED, NONNULL

Reviewed-by: vklang

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

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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@viktorklang-ora) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Nov 29, 2025
@openjdk
Copy link

openjdk bot commented Nov 29, 2025

@kilink The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 29, 2025
@mlbridge
Copy link

mlbridge bot commented Nov 29, 2025

@viktorklang-ora
Copy link
Contributor

Hi @kilink,

This PR is currently missing a test case or two.

@kilink
Copy link
Contributor Author

kilink commented Dec 2, 2025

Hi @kilink,

This PR is currently missing a test case or two.

I've added a basic unit test that verifies the spliterator characteristics as well as the encounter order, let me know if you think that's sufficient. Thanks!

Comment on lines +75 to +79
Spliterator<?> spliterator = enumSet.spliterator();
assertTrue(spliterator.hasCharacteristics(Spliterator.DISTINCT), "Missing DISTINCT");
assertTrue(spliterator.hasCharacteristics(Spliterator.SORTED), "Missing SORTED");
assertTrue(spliterator.hasCharacteristics(Spliterator.ORDERED), "Missing ORDERED");
assertTrue(spliterator.hasCharacteristics(Spliterator.NONNULL), "Missing NONNULL");
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding the test. I think it makes sense to check the enumSet.spliterator().characteristics() being exactly DISTINCT | SORTED | ORDERED | NONNULL (since this test otherwise would still pass if further characteristics are added).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I also check for SIZED / SUBSIZED since those get added by Spliterators.spliterator. I left each check split out though to make it easier to see exactly why the test fails if there's a regression.

@kilink kilink force-pushed the enum-spliterator-characteristics branch from 5750b26 to bcc973e Compare December 2, 2025 23:27
@openjdk
Copy link

openjdk bot commented Dec 2, 2025

@kilink Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information.

public void testSpliteratorCharacteristics() {
assertSpliteratorCharacteristics(EnumSet.allOf(Empty.class));
assertSpliteratorCharacteristics(EnumSet.allOf(Small.class));
assertSpliteratorCharacteristics(EnumSet.allOf(Large.class));
Copy link
Contributor

Choose a reason for hiding this comment

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

For the sake of completeness, it probably makes sense to test the characteristics of EnumSet.of(…), EnumSet.range(…), and EnumSet.noneOf(…) as well.

Copy link
Contributor

@viktorklang-ora viktorklang-ora left a comment

Choose a reason for hiding this comment

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

Thanks for this, @kilink!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 5, 2025
@kilink
Copy link
Contributor Author

kilink commented Dec 5, 2025

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Dec 5, 2025
@openjdk
Copy link

openjdk bot commented Dec 5, 2025

@kilink
Your change (at version adb0183) is now ready to be sponsored by a Committer.

@kilink
Copy link
Contributor Author

kilink commented Dec 5, 2025

Thank you for the review / feedback @viktorklang-ora . Would you be willing to sponsor this change? Thanks!

@viktorklang-ora
Copy link
Contributor

/sponsor

@openjdk
Copy link

openjdk bot commented Dec 6, 2025

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

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Dec 6, 2025

@viktorklang-ora @kilink Pushed as commit 5f083ab.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@jddarcy
Copy link
Member

jddarcy commented Dec 6, 2025

Hmm. Catching up on reviews, should the behavior change here get a CSR? More broader, should there be an implSpec change under a follow-up bug and CSR that requires this behavior?

@viktorklang-ora
Copy link
Contributor

@jddarcy Seems reasonable! Chasing down the super-implementation, Set::spliterator() states that overloads should report their characteristics (even if the documentation linked does seem to unnecessarily convolutedly state which characteristics the default implementation provides). I can open up a new Issue and handle the CSR-bits if @kilink doesn't mind?

@kilink
Copy link
Contributor Author

kilink commented Dec 7, 2025

@jddarcy Seems reasonable! Chasing down the super-implementation, Set::spliterator() states that overloads should report their characteristics (even if the documentation linked does seem to unnecessarily convolutedly state which characteristics the default implementation provides). I can open up a new Issue and handle the CSR-bits if @kilink doesn't mind?

Sounds good to me, thanks! Also, apologies, it hadn't occurred to me that this would require an update to the javadocs. The existing docs do specify that the Iterator returns elements in their natural order, and that null is not permitted, so one could say that it's implied that the spliterator would also have those characteristics. But I do see now that you pointed it out that Set indicates implementations should document any additional characteristics.

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 integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants