diff --git a/CHANGES.txt b/CHANGES.txt index 46f302217d9..5fa60c33b32 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -475,6 +475,7 @@ Release 0.21.0 - Unreleased HBASE-2905 NPE when inserting mass data via REST interface (Sandy Yin via Andrew Purtell) HBASE-2908 Wrong order of null-check [in TIF] (Libor Dener via Stack) + HBASE-2909 SoftValueSortedMap is broken, can generate NPEs IMPROVEMENTS HBASE-1760 Cleanup TODOs in HTable diff --git a/src/main/java/org/apache/hadoop/hbase/util/SoftValue.java b/src/main/java/org/apache/hadoop/hbase/util/SoftValue.java deleted file mode 100644 index f81bc981059..00000000000 --- a/src/main/java/org/apache/hadoop/hbase/util/SoftValue.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright 2010 The Apache Software Foundation - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.hbase.util; - -import java.lang.ref.ReferenceQueue; -import java.lang.ref.SoftReference; -import java.util.Map; - -/** - * A SoftReference derivative so that we can track down what keys to remove. - */ -class SoftValue extends SoftReference implements Map.Entry { - private final K key; - - @SuppressWarnings("unchecked") - SoftValue(K key, V value, ReferenceQueue queue) { - super(value, queue); - this.key = key; - } - - public K getKey() { - return this.key; - } - - public V getValue() { - return get(); - } - - public V setValue(V value) { - throw new RuntimeException("Not implemented"); - } -} \ No newline at end of file diff --git a/src/main/java/org/apache/hadoop/hbase/util/SoftValueMap.java b/src/main/java/org/apache/hadoop/hbase/util/SoftValueMap.java deleted file mode 100644 index 6294a522275..00000000000 --- a/src/main/java/org/apache/hadoop/hbase/util/SoftValueMap.java +++ /dev/null @@ -1,146 +0,0 @@ -/** - * Copyright 2010 The Apache Software Foundation - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.hbase.util; - -import java.lang.ref.ReferenceQueue; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * A Map that uses Soft Reference values internally. Use as a simple cache. - * - * @param key class - * @param value class - */ -public class SoftValueMap implements Map { - private final Map> internalMap = - new HashMap>(); - private final ReferenceQueue rq; - - public SoftValueMap() { - this(new ReferenceQueue()); - } - - public SoftValueMap(final ReferenceQueue rq) { - this.rq = rq; - } - - /** - * Checks soft references and cleans any that have been placed on - * ReferenceQueue. - * @return How many references cleared. - */ - @SuppressWarnings({"unchecked"}) - public int checkReferences() { - int i = 0; - for (Object obj; (obj = this.rq.poll()) != null;) { - i++; - this.internalMap.remove(((SoftValue)obj).getKey()); - } - return i; - } - - public V put(K key, V value) { - checkReferences(); - SoftValue oldValue = this.internalMap.put(key, - new SoftValue(key, value, this.rq)); - return oldValue == null ? null : oldValue.get(); - } - - @SuppressWarnings("unchecked") - public void putAll(Map map) { - throw new RuntimeException("Not implemented"); - } - - @SuppressWarnings({"SuspiciousMethodCalls"}) - public V get(Object key) { - checkReferences(); - SoftValue value = this.internalMap.get(key); - if (value == null) { - return null; - } - if (value.get() == null) { - this.internalMap.remove(key); - return null; - } - return value.get(); - } - - public V remove(Object key) { - checkReferences(); - SoftValue value = this.internalMap.remove(key); - return value == null ? null : value.get(); - } - - public boolean containsKey(Object key) { - checkReferences(); - return this.internalMap.containsKey(key); - } - - public boolean containsValue(Object value) { -/* checkReferences(); - return internalMap.containsValue(value);*/ - throw new UnsupportedOperationException("Don't support containsValue!"); - } - - public boolean isEmpty() { - checkReferences(); - return this.internalMap.isEmpty(); - } - - public int size() { - checkReferences(); - return this.internalMap.size(); - } - - public void clear() { - checkReferences(); - this.internalMap.clear(); - } - - public Set keySet() { - checkReferences(); - return this.internalMap.keySet(); - } - - public Set> entrySet() { - checkReferences(); - Set>> entries = this.internalMap.entrySet(); - Set> real_entries = new HashSet>(); - for(Map.Entry> entry : entries) { - real_entries.add(entry.getValue()); - } - return real_entries; - } - - public Collection values() { - checkReferences(); - Collection> softValues = this.internalMap.values(); - ArrayList hardValues = new ArrayList(); - for(SoftValue softValue : softValues) { - hardValues.add(softValue.get()); - } - return hardValues; - } -} \ No newline at end of file diff --git a/src/main/java/org/apache/hadoop/hbase/util/SoftValueSortedMap.java b/src/main/java/org/apache/hadoop/hbase/util/SoftValueSortedMap.java index 709892c5cdd..4d1a5524c36 100644 --- a/src/main/java/org/apache/hadoop/hbase/util/SoftValueSortedMap.java +++ b/src/main/java/org/apache/hadoop/hbase/util/SoftValueSortedMap.java @@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.util; import java.lang.ref.ReferenceQueue; +import java.lang.ref.SoftReference; import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; @@ -72,7 +73,7 @@ public class SoftValueSortedMap implements SortedMap { for (Object obj; (obj = this.rq.poll()) != null;) { i++; //noinspection unchecked - this.internalMap.remove(((SoftValue)obj).getKey()); + this.internalMap.remove(((SoftValue)obj).key); } return i; } @@ -171,13 +172,7 @@ public class SoftValueSortedMap implements SortedMap { } public synchronized Set> entrySet() { - checkReferences(); - Set>> entries = this.internalMap.entrySet(); - Set> real_entries = new TreeSet>(); - for(Map.Entry> entry : entries) { - real_entries.add(entry.getValue()); - } - return real_entries; + throw new RuntimeException("Not implemented"); } public synchronized Collection values() { @@ -189,4 +184,13 @@ public class SoftValueSortedMap implements SortedMap { } return hardValues; } + + private static class SoftValue extends SoftReference { + final K key; + + SoftValue(K key, V value, ReferenceQueue q) { + super(value, q); + this.key = key; + } + } }