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

Reviewed-by: chegar, naoto, lancea, smarks
This commit is contained in:
Jaikiran Pai 2022-08-11 02:17:01 +00:00
parent 2e0a17c560
commit 4b03e135e1
6 changed files with 41 additions and 2 deletions

View file

@ -394,6 +394,9 @@ public class HashSet<E>
* @since 19
*/
public static <T> HashSet<T> newHashSet(int numElements) {
if (numElements < 0) {
throw new IllegalArgumentException("Negative number of elements: " + numElements);
}
return new HashSet<>(HashMap.calculateHashMapCapacity(numElements));
}