You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by hi...@apache.org on 2010/12/09 11:25:19 UTC
svn commit: r1043885 - in /harmony/enhanced/java/branches/java6: ./
classlib/ classlib/depends/libs/
classlib/modules/luni/src/main/java/java/util/
classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/
drlvm/ jdktools/
Author: hindessm
Date: Thu Dec 9 10:25:19 2010
New Revision: 1043885
URL: http://svn.apache.org/viewvc?rev=1043885&view=rev
Log:
Merge change from /harmony/enhanced/java/trunk@1043880:
r1043880 | tellison | 2010-12-09 10:07:31 +0000 (Thu, 09 Dec 2010) | 2 lines
Apply patch and test case for HARMONY-6419 ([classlib][luni] Changes to IdentityHashMap entrySet doesn't reflect underlying map)
Modified:
harmony/enhanced/java/branches/java6/ (props changed)
harmony/enhanced/java/branches/java6/classlib/ (props changed)
harmony/enhanced/java/branches/java6/classlib/depends/libs/ (props changed)
harmony/enhanced/java/branches/java6/classlib/modules/luni/src/main/java/java/util/IdentityHashMap.java
harmony/enhanced/java/branches/java6/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/IdentityHashMapTest.java
harmony/enhanced/java/branches/java6/drlvm/ (props changed)
harmony/enhanced/java/branches/java6/jdktools/ (props changed)
Propchange: harmony/enhanced/java/branches/java6/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec 9 10:25:19 2010
@@ -1,4 +1,4 @@
/harmony/enhanced/java/branches/mrh:935751-941490
-/harmony/enhanced/java/trunk:929253-1029636,1029773,1029853,1030005,1033407,1035930,1038506,1043349,1043536
+/harmony/enhanced/java/trunk:929253-1029636,1029773,1029853,1030005,1033407,1035930,1038506,1043349,1043536,1043880
/harmony/enhanced/trunk:476395-929252
/incubator/harmony/enhanced/trunk:292550-476394
Propchange: harmony/enhanced/java/branches/java6/classlib/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec 9 10:25:19 2010
@@ -1,7 +1,7 @@
/harmony/enhanced/classlib/trunk:713674-735919,765923-926091,926318-926838
/harmony/enhanced/classlib/trunk/working_classlib:884014-884286
/harmony/enhanced/java/branches/mrh/classlib:935751-941490
-/harmony/enhanced/java/trunk/classlib:929253-1029636,1029773,1029853,1030005,1033407,1035930,1038506,1043349,1043536
+/harmony/enhanced/java/trunk/classlib:929253-1029636,1029773,1029853,1030005,1033407,1035930,1038506,1043349,1043536,1043880
/harmony/enhanced/trunk/classlib:476395-929252
/harmony/enhanced/trunk/working_classlib:476396-920147
/incubator/harmony/enhanced/trunk/classlib:292550-476394
Propchange: harmony/enhanced/java/branches/java6/classlib/depends/libs/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec 9 10:25:19 2010
@@ -1,4 +1,4 @@
/harmony/enhanced/classlib/trunk/depends/libs:544451-926091
-/harmony/enhanced/java/trunk/classlib/depends/libs:929253-1029636,1029773,1029853,1030005,1033407,1035930,1038506,1043349,1043536
+/harmony/enhanced/java/trunk/classlib/depends/libs:929253-1029636,1029773,1029853,1030005,1033407,1035930,1038506,1043349,1043536,1043880
/harmony/enhanced/trunk/classlib/depends/libs:476395-929252
/incubator/harmony/enhanced/trunk/classlib/depends/libs:292550-476394
Modified: harmony/enhanced/java/branches/java6/classlib/modules/luni/src/main/java/java/util/IdentityHashMap.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/luni/src/main/java/java/util/IdentityHashMap.java?rev=1043885&r1=1043884&r2=1043885&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/luni/src/main/java/java/util/IdentityHashMap.java (original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/luni/src/main/java/java/util/IdentityHashMap.java Thu Dec 9 10:25:19 2010
@@ -83,8 +83,16 @@ public class IdentityHashMap<K, V> exten
private static final Object NULL_OBJECT = new Object(); //$NON-LOCK-1$
static class IdentityHashMapEntry<K, V> extends MapEntry<K, V> {
- IdentityHashMapEntry(K theKey, V theValue) {
- super(theKey, theValue);
+
+ final Object iKey;
+
+ final Object[] elementData;
+
+ IdentityHashMapEntry(K theKey, V theValue, Object[] elementData) {
+ super((K) theKey == NULL_OBJECT ? null : theKey,
+ (V) theValue == NULL_OBJECT ? null : theValue);
+ iKey = theKey;
+ this.elementData = elementData;
}
@Override
@@ -98,7 +106,7 @@ public class IdentityHashMap<K, V> exten
return true;
}
if (object instanceof Map.Entry) {
- Map.Entry<?, ?> entry = (Map.Entry) object;
+ Map.Entry<?, ?> entry = (Map.Entry<?, ?>) object;
return (key == entry.getKey()) && (value == entry.getValue());
}
return false;
@@ -114,6 +122,14 @@ public class IdentityHashMap<K, V> exten
public String toString() {
return key + "=" + value; //$NON-NLS-1$
}
+
+ public V setValue(V object) {
+ int index = findIndex(iKey, elementData);
+ if (elementData[index] == key) {
+ elementData[index + 1] = object;
+ }
+ return super.setValue(object);
+ }
}
static class IdentityHashMapIterator<E, KT, VT> implements Iterator<E> {
@@ -208,7 +224,7 @@ public class IdentityHashMap<K, V> exten
@Override
public boolean remove(Object object) {
if (contains(object)) {
- associatedMap.remove(((Map.Entry) object).getKey());
+ associatedMap.remove(((Map.Entry<?, ?>) object).getKey());
return true;
}
return false;
@@ -218,7 +234,7 @@ public class IdentityHashMap<K, V> exten
public boolean contains(Object object) {
if (object instanceof Map.Entry) {
IdentityHashMapEntry<?, ?> entry = associatedMap
- .getEntry(((Map.Entry) object).getKey());
+ .getEntry(((Map.Entry<?, ?>) object).getKey());
// we must call equals on the entry obtained from "this"
return entry != null && entry.equals(object);
}
@@ -397,24 +413,15 @@ public class IdentityHashMap<K, V> exten
*/
@SuppressWarnings("unchecked")
private IdentityHashMapEntry<K, V> getEntry(int index) {
- Object key = elementData[index];
- Object value = elementData[index + 1];
-
- if (key == NULL_OBJECT) {
- key = null;
- }
- if (value == NULL_OBJECT) {
- value = null;
- }
-
- return new IdentityHashMapEntry<K, V>((K) key, (V) value);
+ return new IdentityHashMapEntry<K, V>((K) elementData[index],
+ (V) elementData[index + 1], elementData);
}
/**
* Returns the index where the key is found at, or the index of the next
* empty spot if the key is not found in this table.
*/
- private int findIndex(Object key, Object[] array) {
+ private static int findIndex(Object key, Object[] array) {
int length = array.length;
int index = getModuloHash(key, length);
int last = (index + length - 2) % length;
@@ -431,7 +438,7 @@ public class IdentityHashMap<K, V> exten
return index;
}
- private int getModuloHash(Object key, int length) {
+ private static int getModuloHash(Object key, int length) {
return ((System.identityHashCode(key) & 0x7FFFFFFF) % (length / 2)) * 2;
}
@@ -729,7 +736,7 @@ public class IdentityHashMap<K, V> exten
return true;
}
if (object instanceof Map) {
- Map<?, ?> map = (Map) object;
+ Map<?, ?> map = (Map<?, ?>) object;
if (size() != map.size()) {
return false;
}
@@ -789,7 +796,7 @@ public class IdentityHashMap<K, V> exten
stream.writeInt(size);
Iterator<?> iterator = entrySet().iterator();
while (iterator.hasNext()) {
- MapEntry<?, ?> entry = (MapEntry) iterator.next();
+ MapEntry<?, ?> entry = (MapEntry<?, ?>) iterator.next();
stream.writeObject(entry.key);
stream.writeObject(entry.value);
}
Modified: harmony/enhanced/java/branches/java6/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/IdentityHashMapTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/IdentityHashMapTest.java?rev=1043885&r1=1043884&r2=1043885&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/IdentityHashMapTest.java (original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/IdentityHashMapTest.java Thu Dec 9 10:25:19 2010
@@ -25,6 +25,7 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
+import java.util.Map.Entry;
import org.apache.harmony.testframework.serialization.SerializationTest;
import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
@@ -409,6 +410,25 @@ public class IdentityHashMapTest extends
assertEquals(cloneHashMap, ((IdentityHashMap) cloneHashMap)
.get((Object) null));
}
+
+ /*
+ * Regression test for HARMONY-6419
+ */
+ public void test_underlyingMap() {
+ IdentityHashMap<String, String> ihm = new IdentityHashMap<String, String>();
+ String key = "key";
+ String value = "value";
+ ihm.put(key, value);
+
+ Set<Entry<String, String>> set = ihm.entrySet();
+ assertEquals(1, set.size());
+
+ Entry<String, String> entry = set.iterator().next();
+
+ String newValue = "newvalue";
+ entry.setValue(newValue);
+ assertSame(newValue, ihm.get(key));
+ }
// comparator for IdentityHashMap objects
private static final SerializableAssert COMPARATOR = new SerializableAssert() {
Propchange: harmony/enhanced/java/branches/java6/drlvm/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec 9 10:25:19 2010
@@ -1,5 +1,5 @@
/harmony/enhanced/java/branches/mrh/drlvm:935751-941490
-/harmony/enhanced/java/trunk/drlvm:929253-1029636,1029773,1029853,1030005,1033407,1035930,1038506,1043349,1043536
+/harmony/enhanced/java/trunk/drlvm:929253-1029636,1029773,1029853,1030005,1033407,1035930,1038506,1043349,1043536,1043880
/harmony/enhanced/trunk/drlvm:476395-929252
/harmony/enhanced/trunk/working_vm:476396-920147
/incubator/harmony/enhanced/trunk/drlvm:292550-476394
Propchange: harmony/enhanced/java/branches/java6/jdktools/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec 9 10:25:19 2010
@@ -1,4 +1,4 @@
-/harmony/enhanced/java/trunk/jdktools:929253-1029636,1029773,1029853,1030005,1033407,1035930,1038506,1043349,1043536
+/harmony/enhanced/java/trunk/jdktools:929253-1029636,1029773,1029853,1030005,1033407,1035930,1038506,1043349,1043536,1043880
/harmony/enhanced/jdktools/trunk:630107-925933
/harmony/enhanced/trunk/jdktools:476395-929252
/harmony/enhanced/trunk/working_jdktools:476396-920147