mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +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
|
@ -2578,6 +2578,9 @@ public class HashMap<K,V> extends AbstractMap<K,V>
|
|||
* @since 19
|
||||
*/
|
||||
public static <K, V> HashMap<K, V> newHashMap(int numMappings) {
|
||||
if (numMappings < 0) {
|
||||
throw new IllegalArgumentException("Negative number of mappings: " + numMappings);
|
||||
}
|
||||
return new HashMap<>(calculateHashMapCapacity(numMappings));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue