nikhilkarnwal/cache

Possible NullPointer on class DataStore.java

Opened this issue · 0 comments

The methods get and getExpireTime can thrown NullPointer when cache is cleared by other thread between the invocations of "containsKey" and "get".
You should use only "get" and save it to a variable.
Something like;

public V get(K key) {
    ValueNode v = mKeyValueMap.get(key)
    return v == null ? null : v.Value;
}

Your original code:

public V get(K key) {
    return mKeyValueMap.containsKey(key)?mKeyValueMap.get(key).Value:null;
}

public long getExpireTime(K key){
    return mKeyValueMap.containsKey(key)?mKeyValueMap.get(key).TimeStamp:Long.MAX_VALUE;
}