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

the TreeMap put(key, value) method should replace old value with the new value

    XMLWordPrintable

Details

    • 1.2beta3
    • sparc
    • solaris_2.5.1
    • Not verified

    Description

       When using a TreeMap object, when you call the TreeMap put method
        
       put (key, value)
        
       If there is already an entry with the specified key, the old value for
       that key is supposed to be replaced by the new value.
        
       The code to do so in src/share/classes/java/util/TreeMap.java has a
       bug that causes this not to happen. The code is in the setValue method
       of the Entry inner class (about line 854). It now reads:
        
       public Object setValue (Object v) {
              Object oldValue = this.value;
              this.value = value;
              return oldValue;
       }
        
       but it should read:
        
       public Object setValue (Object v) {
              Object oldValue = this.value;
              this.value = v;
              return oldValue;
       }
        
       I think this serves as a perfect demonstration of why you should name
       member variables something that is not likely to get used in the code
       as an argument or automatic. Like many organizations, we have adopted
       the convention of using an "m_" prefix for member variables.

      Attachments

        Activity

          People

            jjb Josh Bloch
            jbenoit Jonathan Benoit (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: