Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6312056

ConcurrentHashMap.entrySet().iterator() can return entry with never-existent value

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 6
    • core-libs
    • b51
    • generic
    • generic
    • Verified

      This program

      ------------------------------------------------------------
      import java.util.*;
      import java.util.concurrent.*;

      public class Bug {
          public static void main(String[] args) throws Exception {
      Map m = new ConcurrentHashMap();
      m.put(1,2);
      Iterator it = m.entrySet().iterator();
      if (it.hasNext()) {
      m.remove(1); // sneaky
      System.out.println(it.next());
      }
          }
      }
      ------------------------------------------------------------
      prints

      1=null

      which is very surprising, since 1 was never mapped to null,
      and in fact, it could never be.

            martin Martin Buchholz
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: