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

8285405: add test and check for negative argument to HashMap::newHashMap et al #9036

Closed
wants to merge 5 commits into from

Conversation

jaikiran
Copy link
Member

@jaikiran jaikiran commented Jun 6, 2022

Can I please get a review of this change which addresses https://bugs.openjdk.java.net/browse/JDK-8285405?

I've added the test for LinkedHashMap.newLinkedHashMap(int) in the existing test/jdk/java/util/LinkedHashMap/Basic.java since that test has tests for various APIs of this class.

For WeakHashMap.newWeakHashMap and HashMap.newHashMap, I have created new test classes under relevant locations, since these classes already have test classes (almost) per API/feature in those locations.


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-8285405: add test and check for negative argument to HashMap::newHashMap et al

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 9036

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 6, 2022

👋 Welcome back jpai! 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 Jun 6, 2022

@jaikiran 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 core-libs core-libs-dev@openjdk.org label Jun 6, 2022
@jaikiran jaikiran marked this pull request as ready for review June 8, 2022 06:01
@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 8, 2022
@mlbridge
Copy link

mlbridge bot commented Jun 8, 2022

Webrevs

@openjdk
Copy link

openjdk bot commented Jun 8, 2022

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

8285405: add test and check for negative argument to HashMap::newHashMap et al

Reviewed-by: lancea

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

  • dae4c49: 8286197: C2: Optimize MemorySegment shape in int loop
  • 94b473e: 8280454: G1: ClassLoaderData verification keeps CLDs live that causes problems with VerifyDuringGC during Remark

Please see this link for an up-to-date comparison between the source branch of this pull request and 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.

➡️ 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 Jun 8, 2022
@stuart-marks
Copy link
Member

stuart-marks commented Jun 9, 2022

Note that I've integrated JDK-8284780 (HashSet static factories) so maybe this PR could be updated with tests for those as well. Also, if you edit LinkedHashSet.java, please update the copyright date. Forgot to do that in other other PR.

@jaikiran
Copy link
Member Author

Hello Stuart, I'll include tests for those in this PR shortly.

@openjdk-notifier
Copy link

@jaikiran Please do not rebase or force-push to an active PR as it invalidates existing review comments. All changes will be squashed into a single commit automatically when integrating. See OpenJDK Developers’ Guide for more information.

@jaikiran
Copy link
Member Author

I've now update the PR to include tests for HashSet.newHashSet and LinkedHashSet.newLinkedHashSet APIs. Additionally, their implementation too have has been modified to do the necessary negative param check. The copyright year on the LinkedHashSet.java file has also been updated accordingly.

P.S: Please ignore the bot message which talks about rebase/force-push. No rebase or force-push was done (only the recommended merge command was used to merge with latest master branch). I will check with the relevant team to see if there's some bug in the bot which generates that message. I have seen that happen recently on few other PRs as well.

Copy link
Member

@stuart-marks stuart-marks left a comment

Choose a reason for hiding this comment

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

Changes to the files in src are all fine.

I've made a couple individual comments on the NewHashMap.java test. But modifying two files and adding three new files seems rather bulky for what is essentially five copies of the same test. Perhaps they should be consolidated. They could all be written in a single file using a single data provider for five different test methods. (They could even be written as a combo test with a data provider that provides the factory method to call, but that seems like excess complexity.)

I'd suggest adding the data provider and test cases to HashMap/WhiteBoxResizeTest. That test is already testing the factory methods for the five implementations to ensure the right capacity is allocated. Testing them for negative values is only a small step beyond that.

A combo test of {-1, -42, MIN_VALUE} x { newHM, newLHM, ... } doesn't seem to me to warrant the complexity that would entail. Testing different negative values doesn't add much. I'd suggest having a data provider that provides the different factory methods as an IntFunction and then just passes -1 and ensures that the exception is thrown.

return new Object[][]{new Object[]{-1},
new Object[]{Integer.MIN_VALUE},
new Object[]{-42}};
}
Copy link
Member

Choose a reason for hiding this comment

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

Can be rewritten more concisely as follows:

return new Object[][] { { -1 }, { Integer.MIN_VALUE }, { -42 } };

var h = HashMap.newHashMap(val);
assertNotNull(h);
assertEquals(h.size(), 0, "Unexpected size of HashMap created with numMappings: " + val);
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need tests for non-negative values. Aren't these covered in HashMap/WhiteBoxResizeTest? Testing of size is also a bit superfluous here.

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 21, 2022

@jaikiran This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@jaikiran
Copy link
Member Author

Work is in progress, I'll be reviving this shortly.

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 ready Pull request is ready to be integrated rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

3 participants