-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Conversation
👋 Welcome back jpai! A progress list of the required criteria for merging this PR into |
Webrevs
|
@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:
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
Please see this link for an up-to-date comparison between the source branch of this pull request and the ➡️ To integrate this PR with the above commit message to the |
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. |
Hello Stuart, I'll include tests for those in this PR shortly. |
@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. |
I've now update the PR to include tests for 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. |
There was a problem hiding this 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}}; | ||
} |
There was a problem hiding this comment.
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); | ||
} |
There was a problem hiding this comment.
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.
@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! |
Work is in progress, I'll be reviving this shortly. |
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 existingtest/jdk/java/util/LinkedHashMap/Basic.java
since that test has tests for various APIs of this class.For
WeakHashMap.newWeakHashMap
andHashMap.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
Issue
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