You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ns...@apache.org on 2011/10/11 19:43:17 UTC

svn commit: r1181942 - /hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/util/SoftValueSortedMap.java

Author: nspiegelberg
Date: Tue Oct 11 17:43:17 2011
New Revision: 1181942

URL: http://svn.apache.org/viewvc?rev=1181942&view=rev
Log:
Fix the runtime exception when entrySet() is called in SoftValueSortedMap.

Summary:
Currently SoftValueSortedMap.entrySet() tries to iteraate through the entry set
of the underlying map, and put all the values (SoftValue<K,V>) to a newly
created TreeSet<Entry<K,V>>. Because the entry set of SortedMap is already
sorted, so it's not necessary to have a TreeSet to sort those entries again
upon adding. This gets rid of the runtime class cast exception because it does
not require comparing anymore.

Test Plan:
Without the fix, instantiate a SoftValueSortedMap and put three entries in it,
call entrySet().size() would cause it to throw a runtime ClassCastException;
after the fix, it correctly outputs all entries in the sorted order  without
exceptions.

Reviewed By: liyintang
Reviewers: liyintang, kannan
Commenters: kannan
CC: hbase@lists, liyintang, kannan
Differential Revision: 308206
Task ID: 679712

Modified:
    hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/util/SoftValueSortedMap.java

Modified: hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/util/SoftValueSortedMap.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/util/SoftValueSortedMap.java?rev=1181942&r1=1181941&r2=1181942&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/util/SoftValueSortedMap.java (original)
+++ hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/util/SoftValueSortedMap.java Tue Oct 11 17:43:17 2011
@@ -23,11 +23,11 @@ import java.lang.ref.ReferenceQueue;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Comparator;
+import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
 import java.util.SortedMap;
 import java.util.TreeMap;
-import java.util.TreeSet;
 
 /**
  * A SortedMap implementation that uses Soft Reference values
@@ -173,11 +173,11 @@ public class SoftValueSortedMap<K,V> imp
   public synchronized Set<Map.Entry<K,V>> entrySet() {
     checkReferences();
     Set<Map.Entry<K, SoftValue<K,V>>> entries = this.internalMap.entrySet();
-    Set<Map.Entry<K, V>> real_entries = new TreeSet<Map.Entry<K,V>>();
+    Set<Map.Entry<K, V>> realEntries = new LinkedHashSet<Map.Entry<K,V>>();
     for(Map.Entry<K, SoftValue<K,V>> entry : entries) {
-      real_entries.add(entry.getValue());
+      realEntries.add(entry.getValue());
     }
-    return real_entries;
+    return realEntries;
   }
 
   public synchronized Collection<V> values() {