You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by sh...@apache.org on 2017/01/07 02:17:45 UTC

[03/10] kylin git commit: fix NPE bug

fix NPE bug

Signed-off-by: shaofengshi <sh...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/5c9fe955
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/5c9fe955
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/5c9fe955

Branch: refs/heads/sparkcubing-rebase
Commit: 5c9fe9550dcdb4bddcbedb27a12ca0487de9827d
Parents: f573486
Author: xiefan46 <95...@qq.com>
Authored: Thu Jan 5 23:29:43 2017 +0800
Committer: shaofengshi <sh...@apache.org>
Committed: Fri Jan 6 09:38:11 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/5c9fe955/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;
     }