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

Extend WeakHashMap class to disable equals() usage for keys if requested.

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 1.4.0
    • core-libs



      Name: jl125535 Date: 01/28/2003


      FULL PRODUCT VERSION :
      java version "1.4.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
      Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

      FULL OPERATING SYSTEM VERSION :
      Redhat 7.3
      Linux D577A822.kabel.telenet.be 2.4.18-5 #1 Mon Jun 10
      15:31:48 EDT 2002 i686 unknown
      glibc-2.2.5-36


      A DESCRIPTION OF THE PROBLEM :
      The ability to use object identity for the keys in a
      WeakHashMap can be useful for caches. I propose to have an
      extra constructor for this case, with a boolean parameter to
      indicate whether object identity or object equality should
      be used. The default behaviour can then remain the same.

      Example: I'm using a WeakHashMap to hold a cache of proxy
      objects (entry= object->proxy) that are used to translate
      types for method invocations between object created by two
      different classloaders. I do this so that proxy objects are
      reused (1 object, 1 proxy) and the object equality on
      proxies remains valid (if proxy objects are not equal, the
      underlying object are not either and vice versa). BUT, if I
      don't use an adapted version of WeakHashMap, sometimes an
      incorrect proxy object is returned. This happens when the
      object has the same hash key and equals() returns true.


      REPRODUCIBILITY :
      This bug can be reproduced often.

      CUSTOMER WORKAROUND :
      One can create an adapted version of WeakHashMap. The key
      differences are the eq method, and the usage of eq for keys
      throughout the rest of the code (the only place where this
      does not happen yet is in the equals method for entries).
      (Review ID: 158622)
      ======================================================================

            jjb Josh Bloch (Inactive)
            jleesunw Jon Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: