fix NPE bug Signed-off-by: shaofengshi <shaofeng...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/5a18af04 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/5a18af04 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/5a18af04 Branch: refs/heads/master-hbase1.x Commit: 5a18af04ca40aaa6509cdf7c39b71b17dc5eb4a3 Parents: 122b15a Author: xiefan46 <958034...@qq.com> Authored: Thu Jan 5 23:29:43 2017 +0800 Committer: shaofengshi <shaofeng...@apache.org> Committed: Sat Jan 7 10:18:20 2017 +0800 ---------------------------------------------------------------------- .../src/main/java/org/apache/kylin/dict/CacheDictionary.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/5a18af04/core-dictionary/src/main/java/org/apache/kylin/dict/CacheDictionary.java ---------------------------------------------------------------------- diff --git a/core-dictionary/src/main/java/org/apache/kylin/dict/CacheDictionary.java b/core-dictionary/src/main/java/org/apache/kylin/dict/CacheDictionary.java index 1e260b2..d7ed6bd 100644 --- a/core-dictionary/src/main/java/org/apache/kylin/dict/CacheDictionary.java +++ b/core-dictionary/src/main/java/org/apache/kylin/dict/CacheDictionary.java @@ -29,8 +29,6 @@ import java.util.concurrent.ConcurrentHashMap; public abstract class CacheDictionary<T> extends Dictionary<T> { private static final long serialVersionUID = 1L; - protected transient boolean enableValueCache = false; - private transient SoftReference<ConcurrentHashMap> valueToIdCache; private transient SoftReference<Object[]> idToValueCache; @@ -46,7 +44,7 @@ public abstract class CacheDictionary<T> extends Dictionary<T> { //value --> id @Override protected final int getIdFromValueImpl(T value, int roundingFlag) { - if (enableValueCache && roundingFlag == 0) { + if (this.valueToIdCache != null && roundingFlag == 0) { Map cache = valueToIdCache.get(); // SoftReference to skip cache gracefully when short of memory if (cache != null) { Integer id; @@ -66,7 +64,7 @@ public abstract class CacheDictionary<T> extends Dictionary<T> { //id --> value @Override protected final T getValueFromIdImpl(int id) { - if (enableValueCache) { + if (this.idToValueCache != null) { Object[] cache = idToValueCache.get(); if (cache != null) { int seq = calcSeqNoFromId(id); @@ -91,7 +89,6 @@ public abstract class CacheDictionary<T> extends Dictionary<T> { } public final void enableCache() { - this.enableValueCache = true; if (this.valueToIdCache == null) this.valueToIdCache = new SoftReference<>(new ConcurrentHashMap()); if (this.idToValueCache == null) @@ -99,7 +96,6 @@ public abstract class CacheDictionary<T> extends Dictionary<T> { } public final void disableCache() { - this.enableValueCache = false; this.valueToIdCache = null; this.idToValueCache = null; }