mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8285405: add test and check for negative argument to HashMap::newHashMap et al
Reviewed-by: chegar, naoto, lancea, smarks
This commit is contained in:
parent
2e0a17c560
commit
4b03e135e1
6 changed files with 41 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -215,6 +215,9 @@ public class LinkedHashSet<E>
|
|||
* @since 19
|
||||
*/
|
||||
public static <T> LinkedHashSet<T> newLinkedHashSet(int numElements) {
|
||||
if (numElements < 0) {
|
||||
throw new IllegalArgumentException("Negative number of elements: " + numElements);
|
||||
}
|
||||
return new LinkedHashSet<>(HashMap.calculateHashMapCapacity(numElements));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue