Open Bug 990382 Opened 10 years ago Updated 2 years ago

Hash table element is not updated if key already exists.

Categories

(Firefox :: General, defect)

28 Branch
x86_64
Windows 8.1
defect

Tracking

()

UNCONFIRMED

People

(Reporter: modinishank, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0 (Beta/Release)
Build ID: 20140314220517

Steps to reproduce:

Reproducible: Always
      
Steps to Reproduce:-
1.	Define new Hash table of any size.
2.	Inserts a key and a value into the hash table.
3.	Try to update value for the same key in the Hash table.

   Code:- 
     /** insert an element with the specified key
     * overwrite old element if there is already an
     * element with the given key
     * @throws IllegalArgumentException when the table is full
     * @return old element (if any) with key theKey */
   public Object put(Object theKey, Object theElement)
   {
      // search the table for a matching element
      int b = search(theKey);
   
      // check if matching element found
      if (table[b] == null)
      {
         // no matching element and table not full
         table[b] = new HashEntry(theKey, theElement);
         size++;
         return null;
      }
      else
      {// check if duplicate or table full
		  //****	Duplicate element should be updated, ERROR ***
		  if (table[b].key.equals(theKey))
		  {
			  Object elementToReturn = table[b].element;
			  return elementToReturn;
		  }
		  else //table is full
		  {
			  throw new IllegalArgumentException("table is full");}
		  }
   }



Actual results:

Value for the key is not updated.


Expected results:

Value for the key should be updated.
Component: Untriaged → General
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.