< prev index next >

src/java.base/share/classes/java/util/Hashtable.java

Print this page
imported patch loadFactor-isNaN

@@ -182,14 +182,15 @@
      * @exception  IllegalArgumentException  if the initial capacity is less
      *             than zero, or if the load factor is nonpositive.
      */
     public Hashtable(int initialCapacity, float loadFactor) {
         if (initialCapacity < 0)
-            throw new IllegalArgumentException("Illegal Capacity: "+
+            throw new IllegalArgumentException("Illegal Capacity: " +
                                                initialCapacity);
-        if (loadFactor <= 0 || Float.isNaN(loadFactor))
-            throw new IllegalArgumentException("Illegal Load: "+loadFactor);
+        if (!(loadFactor > 0))          // also checks for NaNs
+            throw new IllegalArgumentException("Illegal load factor: " +
+                                               loadFactor);
 
         if (initialCapacity==0)
             initialCapacity = 1;
         this.loadFactor = loadFactor;
         table = new Entry<?,?>[initialCapacity];

@@ -1267,12 +1268,13 @@
             throws IOException, ClassNotFoundException {
         // Read in the threshold and loadFactor
         s.defaultReadObject();
 
         // Validate loadFactor (ignore threshold - it will be re-computed)
-        if (loadFactor <= 0 || Float.isNaN(loadFactor))
-            throw new StreamCorruptedException("Illegal Load: " + loadFactor);
+        if (!(loadFactor > 0))          // also checks for NaNs
+            throw new StreamCorruptedException("Illegal load factor: " +
+                                               loadFactor);
 
         // Read the original length of the array and number of elements
         int origlength = s.readInt();
         int elements = s.readInt();
 
< prev index next >