summaryrefslogtreecommitdiff
path: root/java/util/HashMap.java
diff options
context:
space:
mode:
authorPekka Enberg <penberg@kernel.org>2011-10-30 07:36:38 +0000
committerPekka Enberg <penberg@kernel.org>2011-10-30 07:36:38 +0000
commit5b6355cb81d5404d359b14b6d8cb49a359831094 (patch)
treecc0899bf0c943146f7674de8b2740ffcc3fbe78c /java/util/HashMap.java
parentf3961f046edcdf6fca9897c2a3c0bb406d693ec3 (diff)
downloadclasspath-5b6355cb81d5404d359b14b6d8cb49a359831094.tar.gz
Stefan Ring reports that commit f154af6 ("Fix HashMap.put() to check for
hashCode equality before equals()") breaks running the CACAO test suite. The breakage looks like this: LD_LIBRARY_PATH=../../../src/cacao/.libs ../../../src/cacao/cacao -Xbootclasspath:../../../src/classes/classes:/home/sr/classpathcvs/share/classpath/glibj.zip -classpath /usr/share/java/junit4.jar:. org.junit.runner.JUnitCore All JUnit version 4.5 .E Time: 0.003 There was 1 failure: 1) initializationError(All) java.lang.NullPointerException at java.util.HashMap.put(HashMap.java:348) at java.util.HashSet.add(HashSet.java:151) at org.junit.runners.model.RunnerBuilder.addParent(RunnerBuilder.java:64) at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:81) at org.junit.runners.Suite.<init>(Suite.java:88) at org.junit.runners.Suite.<init>(Suite.java:54) at java.lang.reflect.VMConstructor.construct(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:318) at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:35) at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57) at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57) at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:93) at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:84) at org.junit.runners.Suite.<init>(Suite.java:66) at org.junit.runner.Request.classes(Request.java:68) at org.junit.runner.JUnitCore.run(JUnitCore.java:107) at org.junit.runner.JUnitCore.runMain(JUnitCore.java:88) at org.junit.runner.JUnitCore.runMainAndExit(JUnitCore.java:54) at org.junit.runner.JUnitCore.main(JUnitCore.java:46) FAILURES!!! Tests run: 1, Failures: 1 Looking at the code, it's obviously broken for HashMap.put() with a null key. 2011-10-24 Pekka Enberg <penberg@kernel.org> * java/util/HashMap.java: (put): Fix NullPointerException for null keys.
Diffstat (limited to 'java/util/HashMap.java')
-rw-r--r--java/util/HashMap.java5
1 files changed, 4 insertions, 1 deletions
diff --git a/java/util/HashMap.java b/java/util/HashMap.java
index 9d64fecb4..f5194a240 100644
--- a/java/util/HashMap.java
+++ b/java/util/HashMap.java
@@ -343,9 +343,12 @@ public class HashMap<K, V> extends AbstractMap<K, V>
int idx = hash(key);
HashEntry<K, V> e = buckets[idx];
+ int hash1 = key == null ? 0 : key.hashCode();
while (e != null)
{
- if ((key.hashCode() == e.key.hashCode()) && equals(key, e.key))
+ int hash2 = e.key == null ? 0 : e.key.hashCode();
+
+ if ((hash1 == hash2) && equals(key, e.key))
{
e.access(); // Must call this for bookkeeping in LinkedHashMap.
V r = e.value;