harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r775060 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/IdentityHashMap.java test/api/common/org/apache/harmony/luni/tests/java/util/IdentityHashMap2Test.java
Date Fri, 15 May 2009 09:08:28 GMT
Author: sjanuary
Date: Fri May 15 09:08:28 2009
New Revision: 775060

URL: http://svn.apache.org/viewvc?rev=775060&view=rev
Log:
Apply patch for HARMONY-6204 ([classlib][luni] java.util.IdentityHashMap.<init>(BigNumber)
throws a NegativeArraySizeException while RI throws OutOfMemoryError)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/IdentityHashMap.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/IdentityHashMap2Test.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/IdentityHashMap.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/IdentityHashMap.java?rev=775060&r1=775059&r2=775060&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/IdentityHashMap.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/IdentityHashMap.java
Fri May 15 09:08:28 2009
@@ -267,7 +267,10 @@
     }
 
     private int computeElementArraySize() {
-        return (int) (((long) threshold * 10000) / loadFactor) * 2;
+        int arraySize = (int) (((long) threshold * 10000) / loadFactor) * 2;
+        // ensure arraySize is positive, the above cast from long to int type
+        // leads to overflow and negative arraySize if threshold is too big
+        return arraySize < 0 ? -arraySize : arraySize;
     }
 
     /**

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/IdentityHashMap2Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/IdentityHashMap2Test.java?rev=775060&r1=775059&r2=775060&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/IdentityHashMap2Test.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/IdentityHashMap2Test.java
Fri May 15 09:08:28 2009
@@ -115,6 +115,15 @@
         assertEquals("Size should be 0", 0, hm2.size());
 	}
 
+    public void test_IdentityHashMap_Constructor_BigSize() {
+        try {
+            new IdentityHashMap(Integer.MAX_VALUE);
+            fail("should throw OutOfMemoryError");
+        } catch (OutOfMemoryError e) {
+            // Expected
+        }
+    }
+
 	/**
 	 * @tests java.util.IdentityHashMap#clear()
 	 */



Mime
View raw message