ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/Hashtable/IllegalLoadFactor.java
Revision: 1.7
Committed: Sun Oct 22 02:59:18 2017 UTC (6 years, 7 months ago) by jsr166
Branch: MAIN
Changes since 1.6: +1 -1 lines
Log Message:
fix errorprone [MixedArrayDimensions] warnings

File Contents

# Content
1 /*
2 * Copyright (c) 1997, 1998, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /* @test
25 @bug 4093817 4189594
26 @summary Test for an illegalargumentexception on loadFactor
27 */
28
29 import java.util.*;
30
31 /**
32 * This class tests to see if creating a hash table with an
33 * illegal value of loadFactor results in an IllegalArgumentException
34 */
35 public class IllegalLoadFactor {
36
37 public static void main(String[] args) throws Exception {
38 boolean testSucceeded = false;
39 try {
40 // this should generate an IllegalArgumentException
41 Hashtable bad1 = new Hashtable(100, -3);
42 }
43 catch (IllegalArgumentException e1) {
44 testSucceeded = true;
45 }
46 if (!testSucceeded)
47 throw new Exception("Hashtable, negative load factor");
48
49 testSucceeded = false;
50 try {
51 // this should generate an IllegalArgumentException
52 Hashtable bad1 = new Hashtable(100, Float.NaN);
53 }
54 catch (IllegalArgumentException e1) {
55 testSucceeded = true;
56 }
57 if (!testSucceeded)
58 throw new Exception("Hashtable, NaN load factor");
59
60 testSucceeded = false;
61 try {
62 // this should generate an IllegalArgumentException
63 HashMap bad1 = new HashMap(100, -3);
64 }
65 catch (IllegalArgumentException e1) {
66 testSucceeded = true;
67 }
68 if (!testSucceeded)
69 throw new Exception("HashMap, negative load factor");
70
71 testSucceeded = false;
72 try {
73 // this should generate an IllegalArgumentException
74 HashMap bad1 = new HashMap(100, Float.NaN);
75 }
76 catch (IllegalArgumentException e1) {
77 testSucceeded = true;
78 }
79 if (!testSucceeded)
80 throw new Exception("HashMap, NaN load factor");
81
82
83 testSucceeded = false;
84 try {
85 // this should generate an IllegalArgumentException
86 HashSet bad1 = new HashSet(100, -3);
87 }
88 catch (IllegalArgumentException e1) {
89 testSucceeded = true;
90 }
91 if (!testSucceeded)
92 throw new Exception("HashSet, negative load factor");
93
94 testSucceeded = false;
95 try {
96 // this should generate an IllegalArgumentException
97 HashSet bad1 = new HashSet(100, Float.NaN);
98 }
99 catch (IllegalArgumentException e1) {
100 testSucceeded = true;
101 }
102 if (!testSucceeded)
103 throw new Exception("HashSet, NaN load factor");
104
105 testSucceeded = false;
106 try {
107 // this should generate an IllegalArgumentException
108 WeakHashMap bad1 = new WeakHashMap(100, -3);
109 }
110 catch (IllegalArgumentException e1) {
111 testSucceeded = true;
112 }
113 if (!testSucceeded)
114 throw new Exception("WeakHashMap, negative load factor");
115
116 testSucceeded = false;
117 try {
118 // this should generate an IllegalArgumentException
119 WeakHashMap bad1 = new WeakHashMap(100, Float.NaN);
120 }
121 catch (IllegalArgumentException e1) {
122 testSucceeded = true;
123 }
124 if (!testSucceeded)
125 throw new Exception("WeakHashMap, NaN load factor");
126
127 // Make sure that legal creates don't throw exceptions
128 Map goodMap = new Hashtable(100, .69f);
129 goodMap = new HashMap(100, .69f);
130 Set goodSet = new HashSet(100, .69f);
131 goodMap = new WeakHashMap(100, .69f);
132 }
133 }